diff --git a/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp b/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp index 3ede36fabc..c6dc1cbdd0 100644 --- a/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp @@ -1110,12 +1110,16 @@ public: deleteEditor (true); } - if (chunkMemoryTime > 0 - && chunkMemoryTime < juce::Time::getApproximateMillisecondCounter() - 2000 - && ! recursionCheck) { - chunkMemory.reset(); - chunkMemoryTime = 0; + ScopedLock lock (stateInformationLock); + + if (chunkMemoryTime > 0 + && chunkMemoryTime < juce::Time::getApproximateMillisecondCounter() - 2000 + && ! recursionCheck) + { + chunkMemory.reset(); + chunkMemoryTime = 0; + } } if (editorComp != nullptr) @@ -1857,7 +1861,9 @@ private: auto data = (void**) args.ptr; bool onlyStoreCurrentProgramData = (args.index != 0); + ScopedLock lock (stateInformationLock); chunkMemory.reset(); + if (onlyStoreCurrentProgramData) processor->getCurrentProgramStateInformation (chunkMemory); else @@ -1880,15 +1886,19 @@ private: int32 byteSize = (int32) args.value; bool onlyRestoreCurrentProgramData = (args.index != 0); - chunkMemory.reset(); - chunkMemoryTime = 0; - - if (byteSize > 0 && data != nullptr) { - if (onlyRestoreCurrentProgramData) - processor->setCurrentProgramStateInformation (data, byteSize); - else - processor->setStateInformation (data, byteSize); + ScopedLock lock (stateInformationLock); + + chunkMemory.reset(); + chunkMemoryTime = 0; + + if (byteSize > 0 && data != nullptr) + { + if (onlyRestoreCurrentProgramData) + processor->setCurrentProgramStateInformation (data, byteSize); + else + processor->setStateInformation (data, byteSize); + } } } @@ -2272,8 +2282,9 @@ private: double sampleRate = 44100.0; int32 blockSize = 1024; Vst2::AEffect vstEffect; - juce::MemoryBlock chunkMemory; - juce::uint32 chunkMemoryTime = 0; + CriticalSection stateInformationLock; + MemoryBlock chunkMemory; + uint32 chunkMemoryTime = 0; std::unique_ptr editorComp; Vst2::ERect editorBounds; MidiBuffer midiEvents;