From 9b9c34736562a7dcfb1a5368a7af017eba9c8ac7 Mon Sep 17 00:00:00 2001 From: get-charlie Date: Thu, 6 Aug 2026 14:19:01 +0200 Subject: [PATCH] Fix crash on CloseAudioDevice: uninit device before mutex On Android (AAudio) the callback thread could still run when the mutex was destroyed, causing a SIGABRT (pthread_mutex_lock on a destroyed mutex). Uninit the device first so its callback thread stops before ma_mutex_uninit. --- src/raudio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/raudio.c b/src/raudio.c index 425497acf58e..ec97bdee1246 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -533,8 +533,9 @@ void CloseAudioDevice(void) { if (AUDIO.System.isReady) { - ma_mutex_uninit(&AUDIO.System.lock); + // Stop the device first (joins the callback thread) before destroying the mutex it locks ma_device_uninit(&AUDIO.System.device); + ma_mutex_uninit(&AUDIO.System.lock); ma_context_uninit(&AUDIO.System.context); AUDIO.System.isReady = false;