From 0ff16ddadb387a8751902c850f7af68e027a59da Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 13 Feb 2020 16:47:14 +0000 Subject: [PATCH] Windows: Fixed a potential crash when closing and re-opening WASAPI audio devices --- .../native/juce_win32_WASAPI.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/modules/juce_audio_devices/native/juce_win32_WASAPI.cpp b/modules/juce_audio_devices/native/juce_win32_WASAPI.cpp index d7de74c42d..c461847b32 100644 --- a/modules/juce_audio_devices/native/juce_win32_WASAPI.cpp +++ b/modules/juce_audio_devices/native/juce_win32_WASAPI.cpp @@ -1244,14 +1244,14 @@ public: while (! threadShouldExit()) { - if (outputDevice != nullptr && outputDevice->shouldClose) + if ((outputDevice != nullptr && outputDevice->shouldClose) + || (inputDevice != nullptr && inputDevice->shouldClose)) + { deviceBecameInactive = true; + } if (inputDevice != nullptr && ! deviceBecameInactive) { - if (inputDevice->shouldClose) - deviceBecameInactive = true; - if (outputDevice == nullptr) { if (WaitForSingleObject (inputDevice->clientEvent, 1000) == WAIT_TIMEOUT) @@ -1372,8 +1372,11 @@ private: { if (deviceBecameInactive) { - deviceBecameInactive = false; - MessageManager::callAsync ([this] { reopenDevices(); }); + MessageManager::callAsync ([this] + { + close(); + reopenDevices(); + }); } };