From dcef8b88b20f7b885a647c26784546d54e3b8016 Mon Sep 17 00:00:00 2001 From: reuk Date: Thu, 13 Apr 2023 18:01:01 +0100 Subject: [PATCH] AudioProcessorGraph: Fix race condition when destroying AudioProcessorGraph on a background thread --- .../processors/juce_AudioProcessorGraph.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp b/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp index fd562abd90..ea9b8968ae 100644 --- a/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp +++ b/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp @@ -1677,17 +1677,11 @@ bool AudioProcessorGraph::Connection::operator< (const Connection& other) const } //============================================================================== -class AudioProcessorGraph::Pimpl : public AsyncUpdater +class AudioProcessorGraph::Pimpl { public: explicit Pimpl (AudioProcessorGraph& o) : owner (&o) {} - ~Pimpl() override - { - cancelPendingUpdate(); - clear (UpdateKind::sync); - } - const auto& getNodes() const { return nodes.getNodes(); } void clear (UpdateKind updateKind) @@ -1840,7 +1834,7 @@ public: if (updateKind == UpdateKind::sync && MessageManager::getInstance()->isThisTheMessageThread()) handleAsyncUpdate(); else - triggerAsyncUpdate(); + updater.triggerAsyncUpdate(); } void reset() @@ -1902,7 +1896,7 @@ private: rebuild (updateKind); } - void handleAsyncUpdate() override + void handleAsyncUpdate() { if (const auto newSettings = nodeStates.applySettings (nodes)) { @@ -1933,6 +1927,7 @@ private: RenderSequenceExchange renderSequenceExchange; NodeID lastNodeID; std::optional lastBuiltSequence; + LockingAsyncUpdater updater { [this] { handleAsyncUpdate(); } }; }; //==============================================================================