From a06a220866b9f082b5a29ffc63968f1ab4798814 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Wed, 3 Feb 2021 18:10:18 +0100 Subject: [PATCH] Fix a crash that makes VST fail pluginval --- vst/SfizzVstProcessor.cpp | 18 +++++++++++++++--- vst/SfizzVstProcessor.h | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/vst/SfizzVstProcessor.cpp b/vst/SfizzVstProcessor.cpp index 6a22e52f..ec1d77d0 100644 --- a/vst/SfizzVstProcessor.cpp +++ b/vst/SfizzVstProcessor.cpp @@ -182,6 +182,9 @@ tresult PLUGIN_API SfizzVstProcessor::setActive(TBool state) { sfz::Sfizz* synth = _synth.get(); + if (bool(state) == _isActive) + return kResultTrue; + if (!synth) return kResultFalse; @@ -192,13 +195,13 @@ tresult PLUGIN_API SfizzVstProcessor::setActive(TBool state) _fileChangePeriod = static_cast(1.0 * processSetup.sampleRate); _playStateChangePeriod = static_cast(50e-3 * processSetup.sampleRate); - _workRunning = true; - _worker = std::thread([this]() { doBackgroundWork(); }); + startBackgroundWork(); } else { - synth->allSoundOff(); stopBackgroundWork(); + synth->allSoundOff(); } + _isActive = bool(state); return kResultTrue; } @@ -642,6 +645,15 @@ void SfizzVstProcessor::doBackgroundWork() } } +void SfizzVstProcessor::startBackgroundWork() +{ + if (_workRunning) + return; + + _workRunning = true; + _worker = std::thread([this]() { doBackgroundWork(); }); +} + void SfizzVstProcessor::stopBackgroundWork() { if (!_workRunning) diff --git a/vst/SfizzVstProcessor.h b/vst/SfizzVstProcessor.h index e8408169..1401780b 100644 --- a/vst/SfizzVstProcessor.h +++ b/vst/SfizzVstProcessor.h @@ -48,6 +48,7 @@ public: private: // synth state. acquire processMutex before accessing std::unique_ptr _synth; + bool _isActive = false; SfizzVstState _state; float _currentStretchedTuning = 0; @@ -94,6 +95,7 @@ private: // worker void doBackgroundWork(); + void startBackgroundWork(); void stopBackgroundWork(); // writer bool writeWorkerMessage(const char* type, const void* data, uintptr_t size);