From 09ec1db6f469ebef5c5c199f41b7fd8cc5c559fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Mon, 19 May 2025 15:16:34 -0400 Subject: [PATCH] Fix race condition in `Movie` destructor --- src/display/graphics.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/display/graphics.cpp b/src/display/graphics.cpp index 0f3c880e..c4c7cbe8 100644 --- a/src/display/graphics.cpp +++ b/src/display/graphics.cpp @@ -397,6 +397,12 @@ struct Movie ~Movie() { if (hasAudio) { + audioThreadTermReq.set(); + if(audioThread) { + SDL_WaitThread(audioThread, 0); + audioThread = 0; + } + if (audioQueueTail) { THEORAPLAY_freeAudio(audioQueueTail->audio); } @@ -407,11 +413,6 @@ struct Movie } audioQueueHead = NULL; SDL_DestroyMutex(audioMutex); - audioThreadTermReq.set(); - if(audioThread) { - SDL_WaitThread(audioThread, 0); - audioThread = 0; - } alSourceStop(audioSource); alDeleteSources(1, &audioSource); alDeleteBuffers(STREAM_BUFS, alBuffers);