Window blanks when I click out of it

Started by
6 comments, last by TWild 21 years, 5 months ago
I''m almost finished with my very first DirectX game (thanks to Programming Role-Playing Games With DirectX). I started very simple and made TicTacToe for my niece. Whenever I click outside of my window and come back to it (after lagging a lot), the window is blank. Can anyone tell me why its doing this? I''m using DirectX8.1.
---------------------My specs (because I always forget to post them)Intel P4 2.4 GHz640 MB system memoryRadeon 9700 PROWindows XPDirectX 9DirectX 8.1 SDK
Advertisement
[grrrr.... 500 errors x 2]

OK, it sounds very much like a lost device. This happens when the user switches away from your application, and the video card is no longer being controlled by you (meaning that things stored in its memory like static textures, vertex buffers and index buffers may get replaced or otherwise corrupted).

The solution [correction... a solution] is:
Each frame, before drawing your scene (ie before calling BeginScene), call Device->TestCooperativeLevel() and check the return value.
If it's D3D_OK then obviously everything's fine, and you can draw your scene.
If it's D3DERR_DEVICELOST then the device has been lost, and you should skip this frame.
If it's D3DERR_DEVICENOTRESET then the device has been lost, but it's ready to be reset (you've got the focus again).

To reset the device, you need to:
1) Destroy any textures, vertex buffers and index buffers which are in video memory (created with D3DPOOL_DEFAULT). Also destroy any state-blocks.
2) Call Device->Reset
3) Reload the textures, vertex buffers and state-blocks that you destroyed in step 1

NB: You don't need to do anything to textures or buffers which were created with D3DPOOL_MANAGED - DirectX will reload these automatically.

As you can see, it can be a pain writing robust code to reset the device, but it has two advantages:
1) It means you can handle lost devices properly
2) It means you can change resolution (and toggle fullscreen) without having to restart the game (to do this, just alter the parameters when you call Device->Reset)

Disclaimer:
Of course I could be wrong - it isn't necessarily a lost device.

Hope that helps,

John B

[edited by - JohnBSmall on November 9, 2002 11:16:47 AM]
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
Thanks a ton! I''ll give it a try and post back if it works.
---------------------My specs (because I always forget to post them)Intel P4 2.4 GHz640 MB system memoryRadeon 9700 PROWindows XPDirectX 9DirectX 8.1 SDK
OK, after playing around with it some, I still can''t figure it out. Here is what I did in the GameFrame function. I just wanted to see when the device becomes lost. I test it at the beginning of every frame, and if it becomes lost, it should pop up a message box... (I think, haha) See anything wrong or another way to fix this?


  void cApp::GameFrame(void *Ptr, long Purpose){	cApp *App = (cApp*)Ptr;		if(Purpose == FRAMEPURPOSE){	IDirect3DDevice8 *gDevice;	gDevice = App->m_Graphics.GetDeviceCOM();	if(gDevice->TestCooperativeLevel() == D3DERR_DEVICELOST)		MessageBox(NULL, "Device Lost", "Device Lost", MB_OK);.....  

---------------------My specs (because I always forget to post them)Intel P4 2.4 GHz640 MB system memoryRadeon 9700 PROWindows XPDirectX 9DirectX 8.1 SDK
I also can''t figure out how Jim made it to where the menu screen pops up, pausing the game, whenever the window is not active...
---------------------My specs (because I always forget to post them)Intel P4 2.4 GHz640 MB system memoryRadeon 9700 PROWindows XPDirectX 9DirectX 8.1 SDK
in your MsgLoop():

case WM_ACTIVATE:
{
if (WA_INACTIVE == wParam) // If our program is on the background
g_Active = FALSE;
else // Or if our program is active
g_Active = TRUE;

}break;

g_Active is a bool variable.
Then if g_Active == true, you do your gameloop else:

else
{
WaitMessage();
}

Hope I helped :D
I had the same problem and in my case, it was caught in an infinite loop trying to reactivate the mouse. You might have something similar going on. Is your app fullscreen or windowed?
I haven''t had time to work on it today. Thanks for the replies My app is in a window.
---------------------My specs (because I always forget to post them)Intel P4 2.4 GHz640 MB system memoryRadeon 9700 PROWindows XPDirectX 9DirectX 8.1 SDK

This topic is closed to new replies.

Advertisement