Mercurial > sdl-ios-xcode
diff test/testwin.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 | 153f221b7d48 |
children | 51a8702d8ecd |
line wrap: on
line diff
--- a/test/testwin.c Wed Sep 28 06:38:22 2005 +0000 +++ b/test/testwin.c Wed Sep 28 11:36:20 2005 +0000 @@ -11,6 +11,13 @@ #include "SDL.h" +/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ +static void quit(int rc) +{ + SDL_Quit(); + exit(rc); +} + void DrawPict(SDL_Surface *screen, char *bmpfile, int speedy, int flip, int nofade) { @@ -245,6 +252,13 @@ h = 480; desired_bpp = 0; video_flags = 0; + + if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { + fprintf(stderr, + "Couldn't initialize SDL: %s\n", SDL_GetError()); + return(1); + } + while ( argc > 1 ) { if ( strcmp(argv[1], "-speedy") == 0 ) { speedy = 1; @@ -264,7 +278,7 @@ } else { fprintf(stderr, "The -delay option requires an argument\n"); - exit(1); + quit(1); } } else if ( strcmp(argv[1], "-width") == 0 ) { @@ -274,7 +288,7 @@ } else { fprintf(stderr, "The -width option requires an argument\n"); - exit(1); + quit(1); } } else if ( strcmp(argv[1], "-height") == 0 ) { @@ -284,7 +298,7 @@ } else { fprintf(stderr, "The -height option requires an argument\n"); - exit(1); + quit(1); } } else if ( strcmp(argv[1], "-bpp") == 0 ) { @@ -295,7 +309,7 @@ } else { fprintf(stderr, "The -bpp option requires an argument\n"); - exit(1); + quit(1); } } else if ( strcmp(argv[1], "-warp") == 0 ) { @@ -321,19 +335,12 @@ break; } - if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { - fprintf(stderr, - "Couldn't initialize SDL: %s\n", SDL_GetError()); - exit(1); - } - atexit(SDL_Quit); /* Clean up on exit */ - /* Initialize the display */ screen = SDL_SetVideoMode(w, h, desired_bpp, video_flags); if ( screen == NULL ) { fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n", w, h, desired_bpp, SDL_GetError()); - exit(1); + quit(1); } printf("Set%s %dx%dx%d mode\n", screen->flags & SDL_FULLSCREEN ? " fullscreen" : "", @@ -358,5 +365,6 @@ DrawPict(screen, argv[1], speedy, flip, nofade); #endif SDL_Delay(delay*1000); + SDL_Quit(); return(0); }