The drawing is lost when window is minimized

Started by
5 comments, last by Interminable 11 years, 9 months ago
Hi
I am drawing with directx9, windowed mode. The drawing is in dialog box . The drawing is a simple animation, and the user have option to pause the animation from button click. The problem is following:

1) The animation is paused
2) User minimizes main application
3) when main application window is restored , the drawing is lost i.e the dialog is empty

The drawing is like this ( pseudo code) :

OnBtnClikedPause()
{
paused = true;
}
bool isRunning= true;
while (isRunning)
{
MSG msg;
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
{
isRunning= false;
continue;
}
}
else
{
if( ! paused )
{
scene.Update();
BeginScene();
ClearBuffers();
Draw();
EndScene();
Present();
}
}
}

The updating and drawing of the scenegraph is only if the animation is not paused.

If I change the code , so that I am drawing all the time and only updating if not paused , then I am no longer seeing this problem when restoring back :

if( !paused )
{
scene.Update();
}
BeginScene();
ClearBuffers();
Draw();
EndScene();
Present();


So I don't get it why the rendering in the dialog is lost ?
anyone have idea how to solve the problem without drawing all the time
Advertisement
You're dealing with a lost device, you'll need to draw at least once to get something back up on the screen next to reloading specific resources. You can find more info on the topic here.

You're dealing with a lost device, you'll need to draw at least once to get something back up on the screen next to reloading specific resources. You can find more info on the topic here.


I don't get lost device cause I am checking the return value of Present and throwing exception if it returns that the device is lost, and I don't get exception at all
May have jumped to a conclusion too soon. You could try rendering your scene once after the window gets restored by handling the WM_SIZE message.
Thank you for the suggestion I will do that. But I still don't get why this re-rendering in WM_SIZE is needed at all. Once the drawing is displayed in the window it should stay on the window right ?
If the device is not lost I'd assume it would. Maybe it's the window that needs to repaint, you could try UpdateWindow whenever you detect the window is being restored.
I don't claim to be too knowledgeable here and this may be a dumb question but...when you restore your window, you say it's not drawing anything with your first piece of pseudo code (where functions like Draw(), etc are in the if(!paused) braces). Have you tried debugging it line by line? Is that paused variable still set to true when you restore it? If paused is still set to true then it won't redraw anything until you change that paused flag to false.

I hope this helps. ><

This topic is closed to new replies.

Advertisement