Sign in to follow this  
NeverKnovvsbestt

Unhandled exception Access violation

Recommended Posts

I'm having trouble creating a surface using directX9. The code compiles fine but when i run it i get a message box that says: Unhandled exception at 0x004120b3 in Test.exe: 0xC0000005: Access violation reading location 0x00000000. here's my code: IDirect3DSurface9* DirectXManager::createSurface(int width, int height) { HRESULT hResult; IDirect3DSurface9 *surface; hResult = lpd3dDevice->CreateOffscreenPlainSurface( width, height, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL); if(FAILED(hResult)) return NULL; return surface; }

Share this post


Link to post
Share on other sites
dave    2187
Hey bud,

The first thing i would check is that the instance of DirectXManager is actually alive. I have often overlooked why a method is crashing when the problem has not been the method itself.

If the code in the method doesn't fail and it is not crashing when you are using the returned item, then it is prolly the above.

I hope that helps,

Dave

Share this post


Link to post
Share on other sites
Adam Hamilton    271
The second thing I would check is that lpd3dDevice isn't NULL.

Use an assert like this before you use lpd3dDevice

assert (lpd3dDevice);

It will be removed on release builds but it lets you know if you're about to make a serious runtime error and where it has occured so that you know exactly where you made the mistake.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this