From 7946710bb85c0d410e9e42ffd5a851572cc17a97 Mon Sep 17 00:00:00 2001 From: Tim Felgentreff <timfelgentreff@gmail.com> Date: Fri, 25 Dec 2015 02:21:06 +0100 Subject: [PATCH] Rather than ungracefully killing the audio thread, let the thread cleanup after itself --- src/sound/sound_server.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sound/sound_server.cpp b/src/sound/sound_server.cpp index 337cf1424..bf2556ba0 100644 --- a/src/sound/sound_server.cpp +++ b/src/sound/sound_server.cpp @@ -316,6 +316,7 @@ static void MixIntoBuffer(void *buffer, int samples) */ static void FillAudio(void *, Uint8 *stream, int len) { + if (!Audio.Running) return; Assert(len != Audio.Format.size); SDL_memset(stream, 0, len); @@ -343,6 +344,10 @@ static int FillThread(void *) SDL_UnlockMutex(Audio.Lock); } + SDL_LockMutex(Audio.Lock); + SDL_CloseAudio(); + SDL_DestroyCond(Audio.Cond); + SDL_DestroyMutex(Audio.Lock); return 0; } @@ -858,13 +863,8 @@ int InitSound() */ void QuitSound() { - Audio.Running = false; - SDL_KillThread(Audio.Thread); + Audio.Running = false; - SDL_DestroyCond(Audio.Cond); - SDL_DestroyMutex(Audio.Lock); - - SDL_CloseAudio(); SoundInitialized = false; delete[] Audio.MixerBuffer; Audio.MixerBuffer = NULL;