UpdateSurface and Access Violation
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
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
You should be checking the return values for all of the functions which return any information you rely on. For example:
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.
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'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 :)
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 :)
Quote:Original post by rekotcThis:
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 :)
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).
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).
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
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";
For instance, const wchar_t* path = L"c:/projects/myprojects/mcgiver.bmp";
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement