test/testalpha.c
changeset 1151 be9c9c8f6d53
parent 886 05c551e5bc64
child 1152 51a8702d8ecd
     1.1 --- a/test/testalpha.c	Wed Sep 28 06:38:22 2005 +0000
     1.2 +++ b/test/testalpha.c	Wed Sep 28 11:36:20 2005 +0000
     1.3 @@ -12,6 +12,14 @@
     1.4  
     1.5  #define FRAME_TICKS	(1000/30)		/* 30 frames/second */
     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 +
    1.15  /* Create a "light" -- a yellowish surface with variable alpha */
    1.16  SDL_Surface *CreateLight(SDL_Surface *screen, int radius)
    1.17  {
    1.18 @@ -292,9 +300,8 @@
    1.19  	/* Initialize SDL */
    1.20  	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
    1.21  		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
    1.22 -		exit(1);
    1.23 +		return(1);
    1.24  	}
    1.25 -	atexit(SDL_Quit);
    1.26  
    1.27  	/* Alpha blending doesn't work well at 8-bit color */
    1.28  	info = SDL_GetVideoInfo();
    1.29 @@ -327,7 +334,7 @@
    1.30  			fprintf(stderr, 
    1.31  			"Usage: %s [-bpp N] [-warp] [-hw] [-fullscreen]\n",
    1.32  								argv[0]);
    1.33 -			exit(1);
    1.34 +			quit(1);
    1.35  		}
    1.36  	}
    1.37  
    1.38 @@ -335,14 +342,14 @@
    1.39  	if ( (screen=SDL_SetVideoMode(640,480,video_bpp,videoflags)) == NULL ) {
    1.40  		fprintf(stderr, "Couldn't set 640x480x%d video mode: %s\n",
    1.41  						video_bpp, SDL_GetError());
    1.42 -		exit(2);
    1.43 +		quit(2);
    1.44  	}
    1.45  
    1.46  	/* Set the surface pixels and refresh! */
    1.47  	if ( SDL_LockSurface(screen) < 0 ) {
    1.48  		fprintf(stderr, "Couldn't lock the display surface: %s\n",
    1.49  							SDL_GetError());
    1.50 -		exit(2);
    1.51 +		quit(2);
    1.52  	}
    1.53  	buffer=(Uint8 *)screen->pixels;
    1.54  	if (screen->format->BytesPerPixel!=2) {
    1.55 @@ -371,13 +378,13 @@
    1.56  	/* Create the light */
    1.57  	light = CreateLight(screen, 82);
    1.58  	if ( light == NULL ) {
    1.59 -		exit(1);
    1.60 +		quit(1);
    1.61  	}
    1.62  
    1.63  	/* Load the sprite */
    1.64  	if ( LoadSprite(screen, "icon.bmp") < 0 ) {
    1.65  		SDL_FreeSurface(light);
    1.66 -		exit(1);
    1.67 +		quit(1);
    1.68  	}
    1.69  
    1.70  	/* Print out information about our surfaces */
    1.71 @@ -492,5 +499,7 @@
    1.72  		printf("%d alpha blits, ~%4.4f ms per blit\n", 
    1.73  			flashes, (float)flashtime/flashes);
    1.74  	}
    1.75 +
    1.76 +	SDL_Quit();
    1.77  	return(0);
    1.78  }