UpdateSurface and Access Violation

Started by
17 comments, last by Buckeye 14 years, 8 months ago
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

I love to learn new stuff about computer graphics and the DirectX APIs.

 

Advertisement
Either Surface or BackBuffer is NULL. Do CreateOffscreenPlainSurface() and GetBackBuffer() both succeed?
mmm...i'm not sure, i receive only this error and if i debug the code it stops at the UpdateSurface line

I love to learn new stuff about computer graphics and the DirectX APIs.

 

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.
ok i'm going to check every function...:)...thanks, i'll let you know later, ciao

I love to learn new stuff about computer graphics and the DirectX APIs.

 

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 :)

I love to learn new stuff about computer graphics and the DirectX APIs.

 

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.
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).

I love to learn new stuff about computer graphics and the DirectX APIs.

 

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

I love to learn new stuff about computer graphics and the DirectX APIs.

 

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";

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement