From 695a51832b8c76e9b2542634784d08c91bbb6721 Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 8 Jul 2024 16:47:50 +0100 Subject: [PATCH] VST3 Client: Fix issue where active run loops could be removed incorrectly The same run loop may be registered multiple times, e.g. if the host passes the same run loop pointer to multiple instances of the plugin. When a particular run loop client goes out of scope, it should only remove its own reference to the run loop, because other clients may still be active and still using that run loop. --- .../juce_audio_plugin_client_VST3.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/juce_audio_plugin_client/juce_audio_plugin_client_VST3.cpp b/modules/juce_audio_plugin_client/juce_audio_plugin_client_VST3.cpp index eca9dd6190..61f365c85b 100644 --- a/modules/juce_audio_plugin_client/juce_audio_plugin_client_VST3.cpp +++ b/modules/juce_audio_plugin_client/juce_audio_plugin_client_VST3.cpp @@ -214,7 +214,15 @@ public: void unregisterHandlerForFrame (IPlugFrame* plugFrame) { if (auto* runLoop = getRunLoopFromFrame (plugFrame)) - refreshAttachedEventLoop ([this, runLoop] { hostRunLoops.erase (runLoop); }); + { + refreshAttachedEventLoop ([this, runLoop] + { + const auto it = hostRunLoops.find (runLoop); + + if (it != hostRunLoops.end()) + hostRunLoops.erase (it); + }); + } } /* Asserts if it can be established that the calling thread is different from the host's message