test/testwin.c
changeset 1151 be9c9c8f6d53
parent 228 153f221b7d48
child 1152 51a8702d8ecd
     1.1 --- a/test/testwin.c	Wed Sep 28 06:38:22 2005 +0000
     1.2 +++ b/test/testwin.c	Wed Sep 28 11:36:20 2005 +0000
     1.3 @@ -11,6 +11,13 @@
     1.4  
     1.5  #include "SDL.h"
     1.6  
     1.7 +/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
     1.8 +static void quit(int rc)
     1.9 +{
    1.10 +	SDL_Quit();
    1.11 +	exit(rc);
    1.12 +}
    1.13 +
    1.14  void DrawPict(SDL_Surface *screen, char *bmpfile,
    1.15  					int speedy, int flip, int nofade)
    1.16  {
    1.17 @@ -245,6 +252,13 @@
    1.18  	h = 480;
    1.19  	desired_bpp = 0;
    1.20  	video_flags = 0;
    1.21 +
    1.22 +	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
    1.23 +		fprintf(stderr,
    1.24 +			"Couldn't initialize SDL: %s\n", SDL_GetError());
    1.25 +		return(1);
    1.26 +	}
    1.27 +
    1.28  	while ( argc > 1 ) {
    1.29  		if ( strcmp(argv[1], "-speedy") == 0 ) {
    1.30  			speedy = 1;
    1.31 @@ -264,7 +278,7 @@
    1.32  			} else {
    1.33  				fprintf(stderr,
    1.34  				"The -delay option requires an argument\n");
    1.35 -				exit(1);
    1.36 +				quit(1);
    1.37  			}
    1.38  		} else
    1.39  		if ( strcmp(argv[1], "-width") == 0 ) {
    1.40 @@ -274,7 +288,7 @@
    1.41  			} else {
    1.42  				fprintf(stderr,
    1.43  				"The -width option requires an argument\n");
    1.44 -				exit(1);
    1.45 +				quit(1);
    1.46  			}
    1.47  		} else
    1.48  		if ( strcmp(argv[1], "-height") == 0 ) {
    1.49 @@ -284,7 +298,7 @@
    1.50  			} else {
    1.51  				fprintf(stderr,
    1.52  				"The -height option requires an argument\n");
    1.53 -				exit(1);
    1.54 +				quit(1);
    1.55  			}
    1.56  		} else
    1.57  		if ( strcmp(argv[1], "-bpp") == 0 ) {
    1.58 @@ -295,7 +309,7 @@
    1.59  			} else {
    1.60  				fprintf(stderr,
    1.61  				"The -bpp option requires an argument\n");
    1.62 -				exit(1);
    1.63 +				quit(1);
    1.64  			}
    1.65  		} else
    1.66  		if ( strcmp(argv[1], "-warp") == 0 ) {
    1.67 @@ -321,19 +335,12 @@
    1.68  			break;
    1.69  	}
    1.70  
    1.71 -	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
    1.72 -		fprintf(stderr,
    1.73 -			"Couldn't initialize SDL: %s\n", SDL_GetError());
    1.74 -		exit(1);
    1.75 -	}
    1.76 -	atexit(SDL_Quit);			/* Clean up on exit */
    1.77 -
    1.78  	/* Initialize the display */
    1.79  	screen = SDL_SetVideoMode(w, h, desired_bpp, video_flags);
    1.80  	if ( screen == NULL ) {
    1.81  		fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
    1.82  					w, h, desired_bpp, SDL_GetError());
    1.83 -		exit(1);
    1.84 +		quit(1);
    1.85  	}
    1.86  	printf("Set%s %dx%dx%d mode\n",
    1.87  			screen->flags & SDL_FULLSCREEN ? " fullscreen" : "",
    1.88 @@ -358,5 +365,6 @@
    1.89  	DrawPict(screen, argv[1], speedy, flip, nofade);
    1.90  #endif
    1.91  	SDL_Delay(delay*1000);
    1.92 +	SDL_Quit();
    1.93  	return(0);
    1.94  }