test/testoverlay.c
changeset 1151 be9c9c8f6d53
parent 605 6399f4e90211
child 1439 4d3bb026cd16
     1.1 --- a/test/testoverlay.c	Wed Sep 28 06:38:22 2005 +0000
     1.2 +++ b/test/testoverlay.c	Wed Sep 28 11:36:20 2005 +0000
     1.3 @@ -21,6 +21,13 @@
     1.4  int luminance;
     1.5  int w, 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  /* NOTE: These RGB conversion functions are not intended for speed,
    1.15           only as examples.
    1.16  */
    1.17 @@ -347,7 +354,7 @@
    1.18  			} else {
    1.19  				fprintf(stderr,
    1.20  				"The -delay option requires an argument\n");
    1.21 -				exit(1);
    1.22 +				return(1);
    1.23  			}
    1.24  		} else
    1.25  		if ( strcmp(argv[1], "-width") == 0 ) {
    1.26 @@ -357,7 +364,7 @@
    1.27  			} else {
    1.28  				fprintf(stderr,
    1.29  				"The -width option requires an argument\n");
    1.30 -				exit(1);
    1.31 +				return(1);
    1.32  			}
    1.33  		} else
    1.34  		if ( strcmp(argv[1], "-height") == 0 ) {
    1.35 @@ -367,7 +374,7 @@
    1.36  			} else {
    1.37  				fprintf(stderr,
    1.38  				"The -height option requires an argument\n");
    1.39 -				exit(1);
    1.40 +				return(1);
    1.41  			}
    1.42  		} else
    1.43  		if ( strcmp(argv[1], "-bpp") == 0 ) {
    1.44 @@ -378,7 +385,7 @@
    1.45  			} else {
    1.46  				fprintf(stderr,
    1.47  				"The -bpp option requires an argument\n");
    1.48 -				exit(1);
    1.49 +				return(1);
    1.50  			}
    1.51  		} else
    1.52  		if ( strcmp(argv[1], "-lum") == 0 ) {
    1.53 @@ -389,7 +396,7 @@
    1.54  			} else {
    1.55  				fprintf(stderr,
    1.56  				"The -lum option requires an argument\n");
    1.57 -				exit(1);
    1.58 +				return(1);
    1.59  			}
    1.60  		} else
    1.61  		if ( strcmp(argv[1], "-format") == 0 ) {
    1.62 @@ -407,14 +414,14 @@
    1.63  				else
    1.64  				{
    1.65  					fprintf(stderr, "The -format option %s is not recognized\n",argv[2]);
    1.66 -					exit(1);
    1.67 +					return(1);
    1.68  				}
    1.69  				argv += 2;
    1.70  				argc -= 2;
    1.71  			} else {
    1.72  				fprintf(stderr,
    1.73  				"The -format option requires an argument\n");
    1.74 -				exit(1);
    1.75 +				return(1);
    1.76  			}
    1.77  		} else
    1.78  		if ( strcmp(argv[1], "-hw") == 0 ) {
    1.79 @@ -439,7 +446,7 @@
    1.80  		} else
    1.81  		if (( strcmp(argv[1], "-help") == 0 ) || (strcmp(argv[1], "-h") == 0)) {
    1.82                          PrintUsage(argv0);
    1.83 -                        exit(1);
    1.84 +                        return(1);
    1.85  		} else
    1.86  		if ( strcmp(argv[1], "-fullscreen") == 0 ) {
    1.87  			video_flags |= SDL_FULLSCREEN;
    1.88 @@ -451,16 +458,15 @@
    1.89  	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
    1.90  		fprintf(stderr,
    1.91  			"Couldn't initialize SDL: %s\n", SDL_GetError());
    1.92 -		exit(1);
    1.93 +		return(1);
    1.94  	}
    1.95 -	atexit(SDL_Quit);			/* Clean up on exit */
    1.96  
    1.97  	/* Initialize the display */
    1.98  	screen = SDL_SetVideoMode(w, h, desired_bpp, video_flags);
    1.99  	if ( screen == NULL ) {
   1.100  		fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
   1.101  					w, h, desired_bpp, SDL_GetError());
   1.102 -		exit(1);
   1.103 +		quit(1);
   1.104  	}
   1.105  	printf("Set%s %dx%dx%d mode\n",
   1.106  			screen->flags & SDL_FULLSCREEN ? " fullscreen" : "",
   1.107 @@ -481,7 +487,7 @@
   1.108  	if ( pic == NULL ) {
   1.109  		fprintf(stderr, "Couldn't load %s: %s\n", bmpfile,
   1.110  							SDL_GetError());
   1.111 -		exit(1);
   1.112 +		quit(1);
   1.113  	}
   1.114  
   1.115  	/* Convert the picture to 32bits, for easy conversion */
   1.116 @@ -518,7 +524,7 @@
   1.117  		{
   1.118  			fprintf(stderr, "Couldn't convert picture to 32bits RGB: %s\n",
   1.119  							SDL_GetError());
   1.120 -			exit(1);
   1.121 +			quit(1);
   1.122  		}
   1.123  		SDL_FreeSurface(pic);
   1.124  		pic=newsurf;
   1.125 @@ -528,7 +534,7 @@
   1.126  	overlay = SDL_CreateYUVOverlay(pic->w, pic->h, overlay_format, screen);
   1.127  	if ( overlay == NULL ) {
   1.128  		fprintf(stderr, "Couldn't create overlay: %s\n", SDL_GetError());
   1.129 -		exit(1);
   1.130 +		quit(1);
   1.131  	}
   1.132  	printf("Created %dx%dx%d %s %s overlay\n",overlay->w,overlay->h,overlay->planes,
   1.133  			overlay->hw_overlay?"hardware":"software",
   1.134 @@ -566,7 +572,7 @@
   1.135  			break;
   1.136  		default:
   1.137  			printf("cannot convert RGB picture to obtained YUV format!\n");
   1.138 -			exit(1);
   1.139 +			quit(1);
   1.140  			break;
   1.141  	}
   1.142  #ifdef BENCHMARK_SDL
   1.143 @@ -584,6 +590,7 @@
   1.144  	printf("Time: %d milliseconds\n", now-then);
   1.145  #endif
   1.146  	SDL_Delay(delay*1000);
   1.147 +	SDL_Quit();
   1.148  	return(0);
   1.149  }
   1.150