Marcello Member #1,860



Posted on 08/16/2005 10:27 AM Quote: The first time the game started superb and I could play, but then I looked up the keys (::)) in the readme.txt, and when I tried to restart the game, it crashed all the time. I used the debugger to see where it crashes: In MainGame.cpp, line 20:

gSys->maingame->paused = false; This is because maingame seems to be NULL. Curious, this should be impossible. Here's my reasoning:

1) that line is from inside my alt tab detection code: static void switch_in ( ) { gSys->maingame->paused = false ; } static void switch_out ( ) { gSys->maingame->paused = true ; } 2) those functions are 'initialized' using the following lines, from the constructor of the MainGame class (MainGame.cpp:26): MainGame::MainGame ( ) { set_display_switch_callback ( SWITCH_IN, switch_in ) ; set_display_switch_callback ( SWITCH_OUT, switch_out ) 3) MainGame class is only constructed in one place in the entire game. (A file search finds only one call to new MainGame, and no stack-based instances of the class.) That constructor is in FireStarter::setupGame() (FireStarter.cpp:74):

maingame = new MainGame; 4) Additionally, the global pointer, gSys, points to a FireStarter class, and is initialized in FireStarter's constructor (FireStarter.cpp:18): FireStarter * gSys ; FireStarter::FireStarter ( ) { gSys = this ; game = 0 ; mp = 0 ; datafile = 0 ; } 5) So with all that in mind, gSys is clearly valid before any MainGame's are constructed, and gSys->maingame is set as soon as a MainGame class is constructed. So my conclusion is if somehow a switch-in/out happens in the middle of MainGame's constructor, then I guess the pointer could be invalid. That seems highly improbably, but if that is the case, moving the lines for setting the callback (MainGame's constructor): set_display_switch_callback ( SWITCH_IN, switch_in ) ; set_display_switch_callback ( SWITCH_OUT, switch_out ) ; To MainGame's setup() function, which should only be called after MainGame has been constructed properly (and the gSys->maingame pointer is set), should fix the problem. -- Would 24/32bit be better? Edit FireStarter.cpp and change line 32:

virtual int getScreenBPP() { return 16; }