test/testpalette.c
changeset 1151 be9c9c8f6d53
parent 0 74212992fb08
child 1429 aff0170f9f1b
--- 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;
 }