From 18300abde90f98f5daf9de5b670f48c43595c2a0 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 2 Mar 2022 18:52:27 +0000 Subject: [PATCH] VST3 Client: Add host API checks to setBusArrangements and activateBus --- .../VST3/juce_VST3_Wrapper.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp index e65c66701d..b30ccb8251 100644 --- a/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp @@ -2338,6 +2338,8 @@ public: //============================================================================== tresult PLUGIN_API setActive (TBool state) override { + active = (state != 0); + if (! state) { getPluginInstance().releaseResources(); @@ -2904,6 +2906,9 @@ public: tresult PLUGIN_API activateBus (Vst::MediaType type, Vst::BusDirection dir, Steinberg::int32 index, TBool state) override { + // The host is misbehaving! The plugin must be deactivated before setting new arrangements. + jassert (! active); + if (type == Vst::kEvent) { #if JucePlugin_WantsMidiInput @@ -2979,6 +2984,13 @@ public: tresult PLUGIN_API setBusArrangements (Vst::SpeakerArrangement* inputs, Steinberg::int32 numIns, Vst::SpeakerArrangement* outputs, Steinberg::int32 numOuts) override { + if (active) + { + // The host is misbehaving! The plugin must be deactivated before setting new arrangements. + jassertfalse; + return kResultFalse; + } + auto numInputBuses = pluginInstance->getBusCount (true); auto numOutputBuses = pluginInstance->getBusCount (false); @@ -3536,6 +3548,8 @@ private: AudioBuffer emptyBufferFloat; AudioBuffer emptyBufferDouble; + bool active = false; + #if JucePlugin_WantsMidiInput std::atomic isMidiInputBusEnabled { true }; #endif