Sign in to follow this  
techboy123

strange exception error

Recommended Posts

My program has a access violation error, but the weird thing is that the exception occurs on exit, other than that the program runs fine, the debugger points to this line of code, D3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 0.0f, 0); I've checked my code and can't find what might be causing this,the device is created and released does anyone know what might be causing this?

Share this post


Link to post
Share on other sites
I would imagine you'll find that D3DDevice is an invalid pointer. Do you call that code after you release/cleanup your application?? Step through your code and find out where that pointer gets invalidated.

hth
Jack

Share this post


Link to post
Share on other sites
Thanks for the help I found the solution, for some reason it looks like DirectX doesn't like being destroyed outside of the windows message loop since normally you would do this


switch (message)
{
case WM_DESTROY:
CleanUp();
PostQuitMessage(0);
break;

//other things



}


However I instead did this

void GameCore::ExitGame()
{
GraphicCore.UnLoadImages();
GM = ExGame;
PostMessage(hWnd,WM_DESTROY,NULL,NULL);

}


Now my program works fine thanks for the help

Share this post


Link to post
Share on other sites
Quote:
Original post by techboy123
thanks for the help i found the solution, for some reason it looks like DirectX doesn't like being Destroyed outside of the windows message...
No, you're just using the device pointer after you've released it. WM_DESTROY isn't the last message sent to your window, so doing cleanup there means that you need to have your message proc able to handle your D3D state being non-existant when recieving window messages.
Also, if your message loop looks like this:

while(bRunning)
{
while(PeekMessage())
{
TranslateMessage();
DispatchMessage();
}
Render();
}
You'll see that Render() will be called after you've released all your D3D interfaces, if you do that in WM_DESTROY.

EDIT: Also, using PostMessage() to send a WM_DESTROY message is almost certainly A Bad Thing that is likely to break on future versions of Windows. Use DestroyWindow(hWnd); instead.

Share this post


Link to post
Share on other sites
Thanks for the destroy window tip, the Render shouldn't be called, as it isn't handled since their is a else there

if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )

{
TranslateMessage ( &msg );
DispatchMessage ( &msg );
}
else
{
//idle time
Render();



}

}

Now all I gotta do is replace PostMessage() with DestroyWindow() thanks for the tip

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
EDIT: Also, using PostMessage() to send a WM_DESTROY message is almost certainly A Bad Thing that is likely to break on future versions of Windows. Use DestroyWindow(hWnd); instead.


Indeed. In fact, I just finished making an Evil Steve-esque blog post about it.

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