SDL doesn't exit cleanly!
Posted: Sun Jun 03, 2007 4:25 pm
I have got SDL working and everything now, but it doesn't exit cleanly, it always crashes..
Basically, my layout is that I have my main() thread doing the actual code needed..but for now, it just clears the screen and goes to an infinite loop waiting for the quit_all variable to change to 1 Then I have a SDL thread made for checking and handling the messages of the video display.
here is the main points of my code...(condensed)
btw, nothing with my destructors do stuff with SDL, so that part is safe..
Basically, my layout is that I have my main() thread doing the actual code needed..but for now, it just clears the screen and goes to an infinite loop waiting for the quit_all variable to change to 1 Then I have a SDL thread made for checking and handling the messages of the video display.
here is the main points of my code...(condensed)
Code: Select all
int Thread_Messaging(void * arg){
if( SDL_Init(SDL_INIT_VIDEO) == -1 ){exit(1);}
display.screen=SDL_SetVideoMode(640,480,8,SDL_HWSURFACE);
display.vbuffer=new char[640*480*1];
volatile unsigned int quit=0;
while(quit==0){
display.FlushBuffer();
display.Render();
if(SDL_PollEvent(&event)==1){
switch(event.type){
case SDL_QUIT:
quit=1;
quit_all=1;
exit(0);
break;
}
}else{
//SDL_Delay(50); //don't waste all the processing time..
}
}
quit_all=1;
//SDL_QuitSubSystem(SDL_INIT_VIDEO);
//while(quit_all==1){}
SDL_Quit();
//exit(0);
//while(1){}
}
int main(int argc,char **argv)
#endif
{
// initialize SDL video
fprintf(stderr,"y");
if ( SDL_Init( SDL_INIT_EVENTTHREAD ) < 0 )
{
cout<< "Unable to init SDL: " << SDL_GetError() << endl;
exit(1);
}
// if( SDL_Init(SDL_INIT_VIDEO) == -1 ){exit(1);}
// make sure SDL cleans up before exit
//atexit(SDL_Quit);
// create a new window
messaging=SDL_CreateThread(Thread_Messaging,0);
//disk_cache=SDL_CreateThread(Thread_DiskCache,0);
fprintf(stderr,"t");
cout << "Waiting for SDL...";
SDL_Delay(1000);
cout << endl <<"done!";
DoRobots();
// all is well ;)
while(quit_all==0){
if(quit_all==1){
quit_all++;
SDL_WaitThread(messaging, 0);
SDL_Quit();
}
} //infinite loop...
//while(1){}
return 0;
}