strange exception error

Started by
4 comments, last by MJP 15 years, 8 months ago
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?
Advertisement
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

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

This topic is closed to new replies.

Advertisement