diff test/testpalette.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 74212992fb08
children aff0170f9f1b
line wrap: on
line diff
--- a/test/testpalette.c	Wed Sep 28 06:38:22 2005 +0000
+++ b/test/testpalette.c	Wed Sep 28 11:36:20 2005 +0000
@@ -54,10 +54,17 @@
     {0,39,172}, {0,28,152}, {0,17,132}, {0,7,114}
 };
 
+/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
+static void quit(int rc)
+{
+	SDL_Quit();
+	exit(rc);
+}
+
 static void sdlerr(char *when)
 {
     fprintf(stderr, "SDL error: %s: %s\n", when, SDL_GetError());
-    exit(1);
+    quit(1);
 }
 
 /* create a background surface */
@@ -139,8 +146,6 @@
     if(SDL_Init(SDL_INIT_VIDEO) < 0)
 	sdlerr("initialising SDL");
 
-    atexit(SDL_Quit);
-
     while(--argc) {
 	++argv;
 	if(strcmp(*argv, "-hw") == 0)
@@ -157,7 +162,7 @@
 	    fprintf(stderr,
 		    "usage: testpalette "
 		    " [-hw] [-fullscreen] [-nofade] [-gamma] [-gammaramp]\n");
-	    return 1;
+	    quit(1);
 	}
     }
 
@@ -165,7 +170,7 @@
     if(!(screen = SDL_SetVideoMode(SCRW, SCRH, 8, vidflags | SDL_HWPALETTE))) {
 	fprintf(stderr, "error setting %dx%d 8bpp indexed mode: %s\n",
 		SCRW, SCRH, SDL_GetError());
-	return 1;
+	quit(1);
     }
 
     if(!(boat[0] = SDL_LoadBMP("sail.bmp")))
@@ -327,6 +332,8 @@
 
     printf("%d frames, %.2f fps\n",
 	   frames, 1000.0 * frames / (SDL_GetTicks() - start));
+
+    SDL_Quit();
     return 0;
 }