Skip to content
Permalink
Browse files

VST2: Fixed a potential race condition when getting and setting plug-…

…in state
  • Loading branch information...
tpoole committed Sep 11, 2019
1 parent 6f4d212 commit 1c0eb583f1f201c695c5dedf5ad2c179ed61eb42
Showing with 26 additions and 15 deletions.
  1. +26 −15 modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp
@@ -1110,12 +1110,16 @@ class JuceVSTWrapper : public AudioProcessorListener,
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 @@ class JuceVSTWrapper : public AudioProcessorListener,
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 @@ class JuceVSTWrapper : public AudioProcessorListener,
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 @@ class JuceVSTWrapper : public AudioProcessorListener,
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<EditorCompWrapper> editorComp;
Vst2::ERect editorBounds;
MidiBuffer midiEvents;

0 comments on commit 1c0eb58

Please sign in to comment.
You can’t perform that action at this time.