VST2 plugins: function type mismatch

Running our software with clang’s UBsan enabled I am running into errors caused by the callback functions having a different prototype in the host and the plugin. So far I’ve noticed this with the audioMaster and dispatcher callback.

In aeffect.h, provided by the VST SDK the prototypes are defined as follows:

typedef VstIntPtr(VSTCALLBACK* audioMasterCallback)(AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);
typedef VstIntPtr(VSTCALLBACK* AEffectDispatcherProc)(AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);

The callback implementation as provided by JUCE is in both modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp, where audioMaster is defined as follows:

static pointer_sized_int VSTCALLBACK audioMaster (Vst2::AEffect*, int32, int32, pointer_sized_int, void*, float);

and modules/juce_audio_plugin_client/juce_audio_plugin_client_VST2.cpp, which defines dispatcherCB as follows:

static pointer_sized_int dispatcherCB (Vst2::AEffect* vstInterface, int32 opCode, int32 index,
                                       pointer_sized_int value, void* ptr, float opt)`

If I change those definitions to use Vst2::VstIntPtr instead of pointer_sized_int the errors go away. Turns out that on my system, pointer_sized_int resolves to long long and Vst2::VstIntPtr resolves to long, which is a different type.

There’s probably other things that need to be changed to fix it completely on all platforms. It’s probably best to only use the typedefs as provided by the SDK for the plugins, and not those as defined in juce_MathsFunctions.h.

Why bother with the VST2 format? The SDK was deprecated in 2018, and you are no longer allowed to use it for new releases. The end of VST2 was announced in 2013.

1 Like

I’ve made a pull request to fix the undefined behaviour.

Thanks for reporting this issue. We’ve pushed some patches to fix the problem:

2 Likes

If he has a license for VST2, it’s still valid and he can still release products that support VST. It’s just the rest of us who came late that are, for the most part, not allowed to. :cry:

A lot of people still use VST plugins that they own. I’d love to support it in the pluginhost type thing I’m developing, but I can’t (legally).

Thank you, reuk. That solves the issue for me with some bonus improvements on top!