Original Post
I’ve recently started DirectX programming and have just written my first game. It works fine apart from when I Alt-Tab and restore the game, at which point it crashes. I searched the forum for similar posts to see if anyone had had a similar problem but unfortunately my problem seems different to the many other issues people have had with this.
I’m using the WM_SIZE message to see if the game has been minimised:
I’ve got the below code to stop the GameMain() being run when it’s minimised:
if (RunGameMain)
GameMain();
At the top of GameMain() I’ve got some code to restore the off screen surfaces used in the introduction, title screen and game:
Finally, here’s an example of one of the functions called to restore the surfaces:
When I Alt-Tab to minimise the application the game stops running and everything seems fine, but unfortunately when I maximise the application I just get a black screen. In debug I get the following output.
Direct3D8: (ERROR) :Cannot restore surface, in the middle of a mode change
Direct3D8: (ERROR) :Can''t restore implicitly created surfaces
Direct3D8: (INFO) :NOT Setting DDCAPS_BANKSWITCHED
Direct3D8: (INFO) :Mode was never changed by this app
Direct3D8: (WARN) :Cannot restore surface, not in original mode
Direct3D8: (ERROR) :Can''t restore implicitly created surfaces
Direct3D8: (WARN) :Cannot restore surface, not in original mode
Direct3D8: (WARN) :Cannot restore surface, not in original mode
ddcopybitmap failed
I thought it might be a problem with the primary and back buffer surfaces being restored before the application had maximized so I moved the code to restore these two surfaces to the if (ReloadSurfacaes) bit in GameMain. This changed the debug output slightly (the first two errors go) but it’s still producing a similar problem.
Direct3D8: (INFO) :NOT Setting DDCAPS_BANKSWITCHED
Direct3D8: (INFO) :Mode was never changed by this app
Direct3D8: (WARN) :Cannot restore surface, not in original mode
Direct3D8: (ERROR) :Can''t restore implicitly created surfaces
Direct3D8: (WARN) :Cannot restore surface, not in original mode
Direct3D8: (WARN) :Cannot restore surface, not in original mode
ddcopybitmap failed
Any idea what I’m doing wrong? I can’t work it out at all.
Thanks a lot for any help you can offer.
--
Plague1392
case WM_SIZE:
{
if (wparam == SIZE_MINIMIZED)
{
RunGameMain = false;
}
else if ((wparam == SIZE_MAXIMIZED) || (wparam == SIZE_RESTORED))
{
RunGameMain = true;
ReloadSurfacaes = true;
if (lpDDSurfacePrimary && lpDDSurfacePrimary->IsLost())
lpDDSurfacePrimary->Restore();
if (lpDDSurfaceBack && lpDDSurfaceBack->IsLost())
lpDDSurfaceBack->Restore();
}
return(0);
}break;
if (ReloadSurfacaes)
{
if (Game)
Game->RestoreSurfaces();
else if (Title)
Title->RestoreSurfaces();
else if (Intro)
Intro->RestoreSurfaces();
ReloadSurfacaes = false;
}
void CTitle::RestoreSurfaces()
{
if (PressStartSurfance && PressStartSurfance->IsLost())
{
PressStartSurfance->Restore();
DDReLoadBitmap(PressStartSurfance,
MAKEINTRESOURCE(F_TITLESC_PRESS_ST_TXT));
}
if (SnowManSurface && SnowManSurface->IsLost())
{
SnowManSurface->Restore();
DDReLoadBitmap(SnowManSurface,
MAKEINTRESOURCE(F_TITLESC_SMAN))
}
if (TextTitleSurface && TextTitleSurface->IsLost())
{
TextTitleSurface->Restore();
DDReLoadBitmap(TextTitleSurface,
MAKEINTRESOURCE(F_TITLESC_TEXT_TITLE))
}
}