From 04fe72010fe47ab9b2461c23fe0172ccc9ff72e5 Mon Sep 17 00:00:00 2001 From: David Reid Date: Sun, 22 Aug 2021 09:09:43 +1000 Subject: [PATCH] Experimental fix for an hang when stopping devices. Public issue https://github.com/mackron/miniaudio/issues/355 --- miniaudio.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/miniaudio.h b/miniaudio.h index 900a1883..86670170 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -12673,6 +12673,11 @@ static ma_result ma_device_audio_thread__default_read_write(ma_device* pDevice) } } + /* Make sure we don't get stuck in the inner loop. */ + if (capturedDeviceFramesProcessed == 0) { + break; + } + totalCapturedDeviceFramesProcessed += capturedDeviceFramesProcessed; } } break; @@ -12696,6 +12701,11 @@ static ma_result ma_device_audio_thread__default_read_write(ma_device* pDevice) break; } + /* Make sure we don't get stuck in the inner loop. */ + if (framesProcessed == 0) { + break; + } + ma_device__send_frames_to_client(pDevice, framesProcessed, capturedDeviceData); framesReadThisPeriod += framesProcessed; @@ -12723,6 +12733,11 @@ static ma_result ma_device_audio_thread__default_read_write(ma_device* pDevice) break; } + /* Make sure we don't get stuck in the inner loop. */ + if (framesProcessed == 0) { + break; + } + framesWrittenThisPeriod += framesProcessed; } } break;