As some of you may have seen, I've been having some trouble tracking down a crash that occurs on exit of my game Invasion: Trivia.
I've tracked the problem down to the code I do that displays an effect like a TV shutting off. If I remove the code, no crash occurs. I can't though for the life of me figure out why this is happening.
Let me throw some code your way and see if anyone can spot the problem...
Then, in the StylusUp() handler for my menu screen, I simple do currentScreen = csExiting; so that the proper case executes next time GameLoop() is called and does the TV effect.
As I said... if I simply call Shutdown() from the StylusUp handler instead of doing the TV effect, all is right with the world, but leave that effect in and it blows up. Naturally, it doesn't blow up all the time, it only seems to happen when you get a correct answer while playing the game (I can't figure out the connection... there logically is none, but in either case, removing the above code fixes it).
Any ideas? I assume there's nothing that says you can't call Shutdown() from GameLoop(), right? I think the samples do that, so I'm assuming not. I'm open to any suggestions at this point, if I can't figure it out in a few hours I'm just going to remove the TV effect and update the release, I can live without it (although I really like it!).
Thanks all!
I've tracked the problem down to the code I do that displays an effect like a TV shutting off. If I remove the code, no crash occurs. I can't though for the life of me figure out why this is happening.
Let me throw some code your way and see if anyone can spot the problem...
- Code:
#define csNone 0
#define csMaineMenu 1
#define csExiting 2
// Global vars
bool doShutdown = false;
int ExitCounter = 0;
int currentScreen = csMainMenu;
void InvasionTrivia::GameLoop() {
if (!doShutdown) {
DisplayDevice* display = GetDisplay();
switch (currentScreen) {
... A bunch of cases for various
screens of the game...
case csExiting: {
if (ExitCounter < 120) {
// This section is the part of the effect where
// we draw a line that shrinks down to a dot
display->Clear(Color(0, 0, 0));
display->DrawLine(0 + ExitCounter, 160, 240 -
ExitCounter, 160, Color(255, 255, 255));
ExitCounter = ExitCounter + 12;
} else {
if (ExitFadeCounter <= 0) {
// This section is when we're done with the
// effect and want to exit
doShutdown = true;
currentScreen = csNone;
} else {
// This section is when the line has shrunk to
// a dot, we want to fade that dot off
display->SetBlending(255);
display->Clear(Color(0, 0, 0));
display->SetBlending((char)ExitFadeCounter);
display->SetPixel(120, 160, Color(255, 255, 255));
ExitFadeCounter = ExitFadeCounter - 15;
}
}
break; }
} // End of switch
display->Update();
} else {
// This only executes when we're doing a shutdown
Shutdown();
} // End of if (!doShutdown)
} // End of GameLoop
Then, in the StylusUp() handler for my menu screen, I simple do currentScreen = csExiting; so that the proper case executes next time GameLoop() is called and does the TV effect.
As I said... if I simply call Shutdown() from the StylusUp handler instead of doing the TV effect, all is right with the world, but leave that effect in and it blows up. Naturally, it doesn't blow up all the time, it only seems to happen when you get a correct answer while playing the game (I can't figure out the connection... there logically is none, but in either case, removing the above code fixes it).
Any ideas? I assume there's nothing that says you can't call Shutdown() from GameLoop(), right? I think the samples do that, so I'm assuming not. I'm open to any suggestions at this point, if I can't figure it out in a few hours I'm just going to remove the TV effect and update the release, I can live without it (although I really like it!).
Thanks all!