Commit 284df27b5a56ed64f5b1993b20b25d5cbae7000d

Sam Lantinga 2022-10-23T16:34:32

Merge commit 'e7ab581d796aa83f7d028ea4249fdc66600df173' into main

diff --git a/src/audio/coreaudio/SDL_coreaudio.m b/src/audio/coreaudio/SDL_coreaudio.m
index 6cfc035..dbd85f4 100644
--- a/src/audio/coreaudio/SDL_coreaudio.m
+++ b/src/audio/coreaudio/SDL_coreaudio.m
@@ -704,6 +704,11 @@ COREAUDIO_CloseDevice(_THIS)
     /* if callback fires again, feed silence; don't call into the app. */
     SDL_AtomicSet(&this->paused, 1);
 
+    /* dispose of the audio queue before waiting on the thread, or it might stall for a long time! */
+    if (this->hidden->audioQueue) {
+        AudioQueueDispose(this->hidden->audioQueue, 0);
+    }
+
     if (this->hidden->thread) {
         SDL_assert(SDL_AtomicGet(&this->shutdown) != 0);  /* should have been set by SDL_audio.c */
         SDL_WaitThread(this->hidden->thread, NULL);
@@ -733,10 +738,6 @@ COREAUDIO_CloseDevice(_THIS)
         open_devices = NULL;
     }
 
-    if (this->hidden->audioQueue) {
-        AudioQueueDispose(this->hidden->audioQueue, 1);
-    }
-
     if (this->hidden->ready_semaphore) {
         SDL_DestroySemaphore(this->hidden->ready_semaphore);
     }