Freezing on exit

Greetings,

my SDL is freezing (getting stuck but not crashing) during my audio 

shutdown, the call stack follows:

SDL_SYS_WaitThread(SDL_Thread * 0x00941b50)
SDL_WaitThread(SDL_Thread * 0x00941b50, int * 0x00000000)
SDL_AudioQuit()
SDL_QuitSubSystem(unsigned int 0x00000010)
SDL_CloseAudio()
Mix_CloseAudio()
SDL_main(int 0x00000001, char * * 0x0081fd5c)
main(int 0x00000001, char * * 0x0081fd5c)


this results from the following fragment:

{
	// automatically clean up on exit.
	atexit(SDL_Quit);

	// init
	SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO);

	// open video
	SDL_Surface *screen = SDL_SetVideoMode(640, 480,
						16, SDL_HWSURFACE);
	assert(screen);

	// open the audio device.
	Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT,
			MIX_DEFAULT_CHANNELS, 4096);

	Mix_Chunk *wav = Mix_LoadWAV("Slip.wav");
	assert(wav);

	Mix_PlayChannel(-1, wav, 10);

	// let it play a while.
	SDL_Delay(3000);

	Mix_FreeChunk(wav);

	// clean up
	Mix_CloseAudio();
	SDL_Quit();


}

Notes:
1) it doesn't occur if i don't call SDL_SetVideoMode.
2) it works fine on NT4 and win2k.
3) i first noticed it after installing DX8.
4) could it have to do with the INFINITE time out in SDL_SYS_WaitThread ?

thank you.

-dv

Daniel:

I’m not sure if it’s the cause of your problems, but I did notice
something peculiar I thought I’d ask about.

The first thing you do is atexit(SDL_Quit). But you ALSO call SDL_Quit
explicitly at the end of the code. Wouldn’t this cause SDL_Quit to be
called twice? Even so, I can’t imagine that this would hang your
program. Perhaps my understanding of this area is a little foggy,
but I thought I’d throw it out there. (Hmmm…more another question than
an answer to yours…sorry)

LyleOn Wed, 29 Nov 2000, Daniel wrote:

this results from the following fragment:

{
// automatically clean up on exit.
atexit(SDL_Quit);

  // init
  SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO);

  // open video
  SDL_Surface *screen = SDL_SetVideoMode(640, 480,
  					16, SDL_HWSURFACE);
  assert(screen);

  // open the audio device.
  Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT,
  		MIX_DEFAULT_CHANNELS, 4096);

  Mix_Chunk *wav = Mix_LoadWAV("Slip.wav");
  assert(wav);

  Mix_PlayChannel(-1, wav, 10);

  // let it play a while.
  SDL_Delay(3000);

  Mix_FreeChunk(wav);

  // clean up
  Mix_CloseAudio();
  SDL_Quit();

}

Notes:

  1. it doesn’t occur if i don’t call SDL_SetVideoMode.
  2. it works fine on NT4 and win2k.
  3. i first noticed it after installing DX8.
  4. could it have to do with the INFINITE time out in SDL_SYS_WaitThread ?

thank you.

-dv

I’m not sure if it’s the cause of your problems, but I did notice
something peculiar I thought I’d ask about.

The first thing you do is atexit(SDL_Quit). But you ALSO call SDL_Quit
explicitly at the end of the code. Wouldn’t this cause SDL_Quit to be
called twice?

yes, however sdl is smart enough to do nothing during the second call 

(see the SDL_QuitSubSystem(SDL_INIT_EVERYTHING) code in SDL.c). the reason i
call SDL_Quit explicitly at the end of the code is because i like balancing my
init/free pairs whenever possible. it is more consistent, easier to pick
faults, and if i ever cut and paste code i can be more confident i get
everything i need in one hit.

Even so, I can’t imagine that this would hang your
program. Perhaps my understanding of this area is a little foggy,
but I thought I’d throw it out there.

if you look at the call stack you'll see it freezes in SDL_SYS_WaitThread 

not SDL_Quit.

-dv

my SDL is freezing (getting stuck but not crashing) during my audio
shutdown, the call stack follows:

SDL_SYS_WaitThread(SDL_Thread * 0x00941b50)
SDL_WaitThread(SDL_Thread * 0x00941b50, int * 0x00000000)
SDL_AudioQuit()
SDL_QuitSubSystem(unsigned int 0x00000010)
SDL_CloseAudio()
Mix_CloseAudio()
SDL_main(int 0x00000001, char * * 0x0081fd5c)
main(int 0x00000001, char * * 0x0081fd5c)

It sounds like you’re trying to shut down the audio while the audio
is locked. I’m not sure where that would happen with the mixer library.
Are you doing any multi-threaded sound operations?

Try printing out a message from within the audio mixing loop and
see if it’s actually running.

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Hi,

The first thing you do is atexit(SDL_Quit). But you ALSO call SDL_Quit
explicitly at the end of the code. Wouldn’t this cause SDL_Quit to be
called twice? Even so, I can’t imagine that this would hang your
program. Perhaps my understanding of this area is a little foggy,
but I thought I’d throw it out there. (Hmmm…more another question than
an answer to yours…sorry)

I had the same prob too: I registered SDL_Quit atexit() and I called it
explicitly… I removed the explicit call and everything went fine…

cu
– Alex

Hi,

The first thing you do is atexit(SDL_Quit). But you ALSO call SDL_Quit
explicitly at the end of the code. Wouldn’t this cause SDL_Quit to be
called twice? Even so, I can’t imagine that this would hang your
program. Perhaps my understanding of this area is a little foggy,
but I thought I’d throw it out there. (Hmmm…more another question than
an answer to yours…sorry)

I had the same prob too: I registered SDL_Quit atexit() and I called it
explicitly… I removed the explicit call and everything went fine…

It shouldn’t be necessary with SDL 1.1.5 and newer.

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software