comparison test/testwm.c @ 1151:be9c9c8f6d53

Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe if SDL is built with a non-cdecl calling convention, and it's just generally bad practice anyhow. Now programs explicitly call SDL_Quit() where appropriate, wrap SDL_Quit() in a cdecl function where it can't be avoided, and rely on the parachute where a crash might have hit the atexit() before (these ARE test programs, after all!).
author Ryan C. Gordon <icculus@icculus.org>
date Wed, 28 Sep 2005 11:36:20 +0000
parents 3eddf51b649b
children 08e3393e9ffb
comparison
equal deleted inserted replaced
1150:7d8e1925f35b 1151:be9c9c8f6d53
10 /* Is the cursor visible? */ 10 /* Is the cursor visible? */
11 static int visible = 1; 11 static int visible = 1;
12 12
13 static Uint8 video_bpp; 13 static Uint8 video_bpp;
14 static Uint32 video_flags; 14 static Uint32 video_flags;
15
16 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
17 static void quit(int rc)
18 {
19 SDL_Quit();
20 exit(rc);
21 }
15 22
16 int SetVideoMode(int w, int h) 23 int SetVideoMode(int w, int h)
17 { 24 {
18 SDL_Surface *screen; 25 SDL_Surface *screen;
19 int i; 26 int i;
262 int w, h; 269 int w, h;
263 270
264 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { 271 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
265 fprintf(stderr, 272 fprintf(stderr,
266 "Couldn't initialize SDL: %s\n", SDL_GetError()); 273 "Couldn't initialize SDL: %s\n", SDL_GetError());
267 exit(1); 274 return(1);
268 } 275 }
269 atexit(SDL_Quit);
270 276
271 /* Check command line arguments */ 277 /* Check command line arguments */
272 w = 640; 278 w = 640;
273 h = 480; 279 h = 480;
274 video_bpp = 8; 280 video_bpp = 8;
331 else 337 else
332 printf("No window title was set!\n"); 338 printf("No window title was set!\n");
333 339
334 /* Initialize the display */ 340 /* Initialize the display */
335 if ( SetVideoMode(w, h) < 0 ) { 341 if ( SetVideoMode(w, h) < 0 ) {
336 return(1); 342 quit(1);
337 } 343 }
338 344
339 /* Set an event filter that discards everything but QUIT */ 345 /* Set an event filter that discards everything but QUIT */
340 SDL_SetEventFilter(FilterEvents); 346 SDL_SetEventFilter(FilterEvents);
341 347
353 case SDL_USEREVENT: 359 case SDL_USEREVENT:
354 printf("Handling internal quit request\n"); 360 printf("Handling internal quit request\n");
355 /* Fall through to the quit handler */ 361 /* Fall through to the quit handler */
356 case SDL_QUIT: 362 case SDL_QUIT:
357 printf("Bye bye..\n"); 363 printf("Bye bye..\n");
358 return(0); 364 quit(0);
359 default: 365 default:
360 /* This should never happen */ 366 /* This should never happen */
361 printf("Warning: Event %d wasn't filtered\n", 367 printf("Warning: Event %d wasn't filtered\n",
362 event.type); 368 event.type);
363 break; 369 break;
364 } 370 }
365 } 371 }
366 printf("SDL_WaitEvent() error: %s\n", SDL_GetError()); 372 printf("SDL_WaitEvent() error: %s\n", SDL_GetError());
373 SDL_Quit();
367 return(255); 374 return(255);
368 } 375 }