From f769b1815797bf500ee8fc371c8893f348d0b423 Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 19 Jan 2022 17:50:34 +1000 Subject: [PATCH] WASAPI: Fix an error where a buffer can possible be unreleased. --- CHANGES.md | 1 + miniaudio.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 01a31133..95650d5c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,6 @@ v0.11.6 - TBD ==================== +* WASAPI: Fix a bug where the device is not stopped when an error occurrs when writing to a playback device. * The node graph can now be used as a node. This allows node graphs to be connected to other node graphs. * Fix a crash with high-pass and band-pass filters. * Fix an audio glitch when mixing engine nodes (ma_sound and ma_sound_group). diff --git a/miniaudio.h b/miniaudio.h index 343fcc2e..1be1793b 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -20842,9 +20842,23 @@ static ma_result ma_device_uninit__wasapi(ma_device* pDevice) #endif if (pDevice->wasapi.pRenderClient) { + if (pDevice->wasapi.pMappedBufferPlayback != NULL) { + ma_IAudioRenderClient_ReleaseBuffer((ma_IAudioRenderClient*)pDevice->wasapi.pRenderClient, pDevice->wasapi.mappedBufferPlaybackCap, 0); + pDevice->wasapi.pMappedBufferPlayback = NULL; + pDevice->wasapi.mappedBufferPlaybackCap = 0; + pDevice->wasapi.mappedBufferPlaybackLen = 0; + } + ma_IAudioRenderClient_Release((ma_IAudioRenderClient*)pDevice->wasapi.pRenderClient); } if (pDevice->wasapi.pCaptureClient) { + if (pDevice->wasapi.pMappedBufferCapture != NULL) { + ma_IAudioCaptureClient_ReleaseBuffer((ma_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient, pDevice->wasapi.mappedBufferCaptureCap); + pDevice->wasapi.pMappedBufferCapture = NULL; + pDevice->wasapi.mappedBufferCaptureCap = 0; + pDevice->wasapi.mappedBufferCaptureLen = 0; + } + ma_IAudioCaptureClient_Release((ma_IAudioCaptureClient*)pDevice->wasapi.pCaptureClient); }