Jump to content
  • Advertisement
Sign in to follow this  
rekotc

UpdateSurface and Access Violation

This topic is 3226 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello everybody, i'm quite new to directX, i'm simply trying to load a .bmp in a surface, but it gives me back a memory access violation (Null pointer??) here is the code: const wchar_t* path = L"./mcgiver.mbmp"; D3DXIMAGE_INFO Info; D3DXGetImageInfoFromFile(path, &Info); g_pd3dDevice->CreateOffscreenPlainSurface(Info.Width, Info.Height, Info.Format, D3DPOOL_SYSTEMMEM, &Surface, NULL); D3DXLoadSurfaceFromFile(Surface, NULL, NULL, path,NULL, D3DX_FILTER_NONE, 0, NULL); if ( SUCCEEDED (g_pd3dDevice->BeginScene())) { IDirect3DSurface9 *BackBuffer = NULL; g_pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &BackBuffer); g_pd3dDevice->UpdateSurface(Surface, NULL, BackBuffer, NULL); g_pd3dDevice->EndScene(); } the error is at UpdateSurface(Surface, NULL, BackBuffer, NULL), and i'm sure it's because of the Surface object, but i cant understand why, this is the exact error: Unhandled exception at 0x743b65d0 in DX9GRAPHICS_1.exe: 0xC0000005: Access violation reading location 0x00000000. can u help me? :) thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
mmm...i'm not sure, i receive only this error and if i debug the code it stops at the UpdateSurface line

Share this post


Link to post
Share on other sites
You should be checking the return values for all of the functions which return any information you rely on. For example:

if(SUCCEEDED(g_pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &BackBuffer))
g_pd3dDevice->UpdateSurface(Surface, NULL, BackBuffer, NULL);


The Debug Runtimes will help you find out what's causing the error once you've diagnosed it.

Also, remember that you should be prepared for any D3D call to fail on the target platform, and should at least be able to shut down gracefully.

Share this post


Link to post
Share on other sites
ok i've found something...i think.., i added this lines ( i know maybe it's a stupid idea but i'm still learning everything)

if( D3DXGetImageInfoFromFile(path, &Info)!= D3D_OK )
{

int msgboxID = MessageBox(
NULL,
(LPCWSTR)L"something wrong here",
(LPCWSTR)L"Error",
MB_ICONWARNING
);

}

and actually the message box shows up, so at least i have a problem here, maybe something very stupid...like the path?, because i cant figure out something different, thanks again :)

Share this post


Link to post
Share on other sites
Quote:
Original post by rekotc
ok i've found something...i think.., i added this lines ( i know maybe it's a stupid idea but i'm still learning everything)

if( D3DXGetImageInfoFromFile(path, &Info)!= D3D_OK )
{

int msgboxID = MessageBox(
NULL,
(LPCWSTR)L"something wrong here",
(LPCWSTR)L"Error",
MB_ICONWARNING
);

}

and actually the message box shows up, so at least i have a problem here, maybe something very stupid...like the path?, because i cant figure out something different, thanks again :)
This:
if( D3DXGetImageInfoFromFile(path, &Info)!= D3D_OK )
Should be:
if(FAILED(D3DXGetImageInfoFromFile(path, &Info)))
Since there's 2 billion possible success codes, not just D3D_OK. For the actual problem, that function failing is usually caused by the path being invalid - again, the debug runtimes (Specifically d3dx9d.lib) will tell you exactly what the error is.

Share this post


Link to post
Share on other sites
mmm, i've chosen D3D_OK simply because i found this on the msdn website:

Return Values

If the function succeeds, the return value is D3D_OK. If the function fails, the return value can be the following: D3DERR_INVALIDCALL

anyway even with FAILED i have the same result, with the debug runtimes i get :


Direct3D9: (ERROR) :This format is not supported for offscreen plain surfaces. CreateOffscreenPlainSurface fails.
Direct3D9: (ERROR) :NULL surface interface specified. UpdateSurface fails
Direct3D9: (ERROR) :This format is not supported for offscreen plain surfaces. CreateOffscreenPlainSurface fails.
Direct3D9: (ERROR) :NULL surface interface specified. UpdateSurface fails
The program '[1636] DX9GRAPHICS_1.exe: Native' has exited with code 0 (0x0).

Share this post


Link to post
Share on other sites
also...i'm an idiot.....it couldnt find the picture because i wrote .mbmp instead of .bmp, now the message box doesnt show up, but i still get the same errors

Share this post


Link to post
Share on other sites
The path you're using is a relative path to the current directory. Just to be sure, try changing your path to a full path including the drive, directories, etc.

For instance, const wchar_t* path = L"c:/projects/myprojects/mcgiver.bmp";

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!