Advertisement Jump to content


This topic is now archived and is closed to further replies.


Why does my program have a stupid bug in it?

This topic is 7120 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The problem is that when you Alt-TAB out of a program and back into it, your DD surfaces are lost, so then when you try to use them, you get NULL pointer problems.

The solution is to have a way to restore surfaces. The best way I have found to handle this is to have a global variable to keep track of whether your app has the focus (i.e., for a non-Windowed mode game, it is not minimized). This flag can be set by handling the WM_ACTIVATEAPP message if (wparam will be TRUE if the app is gaining the focus, false if it is being minimized). When your app is inactive, you want to skip the game loop. When it switches to active from inactive, you want to call a routine to restore your surfaces. This routine will check every surface you have to see if the surface has been lost (use IsLost() to check and Restore() to restore). You will then have to reload the images you had in those surfaces; modularization of your image loading makes this a lot easier.

Share this post

Link to post
Share on other sites
Ok, I've done a tetris game like that article
says, but one little thing. I've done it in
Windows using Direct-X, and I am neither a
Direct-X programmer nor a Windows programmer.

For some reason, when you ALT-TAB out of the
program, then ALT-TAB back in, it freezes the
whole damn computer. Why could this be?

Any help would be appreciated.

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Ahh, I was restoring my primary suface & the
back buffer, but not my sprites. Thanks for
that. I can use the WM_ACTIVATEAPP to set
my paused flag, just like in those dodgy Microsoft games.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!