test/loopwave.c
changeset 1151 be9c9c8f6d53
parent 0 74212992fb08
child 1463 0394f8ebc42d
     1.1 --- a/test/loopwave.c	Wed Sep 28 06:38:22 2005 +0000
     1.2 +++ b/test/loopwave.c	Wed Sep 28 11:36:20 2005 +0000
     1.3 @@ -19,6 +19,15 @@
     1.4  	int      soundpos;		/* Current play position */
     1.5  } wave;
     1.6  
     1.7 +
     1.8 +/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
     1.9 +static void quit(int rc)
    1.10 +{
    1.11 +	SDL_Quit();
    1.12 +	exit(rc);
    1.13 +}
    1.14 +
    1.15 +
    1.16  void fillerup(void *unused, Uint8 *stream, int len)
    1.17  {
    1.18  	Uint8 *waveptr;
    1.19 @@ -54,13 +63,12 @@
    1.20  	/* Load the SDL library */
    1.21  	if ( SDL_Init(SDL_INIT_AUDIO) < 0 ) {
    1.22  		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
    1.23 -		exit(1);
    1.24 +		return(1);
    1.25  	}
    1.26 -	atexit(SDL_Quit);
    1.27  
    1.28  	if ( argv[1] == NULL ) {
    1.29  		fprintf(stderr, "Usage: %s <wavefile>\n", argv[0]);
    1.30 -		exit(1);
    1.31 +		quit(1);
    1.32  	}
    1.33  
    1.34  	/* Load the wave file into memory */
    1.35 @@ -68,7 +76,7 @@
    1.36  			&wave.spec, &wave.sound, &wave.soundlen) == NULL ) {
    1.37  		fprintf(stderr, "Couldn't load %s: %s\n",
    1.38  						argv[1], SDL_GetError());
    1.39 -		exit(1);
    1.40 +		quit(1);
    1.41  	}
    1.42  	wave.spec.callback = fillerup;
    1.43  
    1.44 @@ -86,7 +94,7 @@
    1.45  	if ( SDL_OpenAudio(&wave.spec, NULL) < 0 ) {
    1.46  		fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
    1.47  		SDL_FreeWAV(wave.sound);
    1.48 -		exit(2);
    1.49 +		quit(2);
    1.50  	}
    1.51  	SDL_PauseAudio(0);
    1.52  
    1.53 @@ -98,5 +106,6 @@
    1.54  	/* Clean up on signal */
    1.55  	SDL_CloseAudio();
    1.56  	SDL_FreeWAV(wave.sound);
    1.57 +	SDL_Quit();
    1.58  	return(0);
    1.59  }