A fix for bug/improvement in VSTPluginInstance

Posting this partly to suggest an improvement, and partly to get confirmation that I’m right.
Got some non-juce plugins that crash when removed/freed from my host.
This relates to a Juce call to a Timer callback in VSTPluginInstance:

void timerCallback() override
    if (dispatch (effIdle, 0, 0, 0, 0) == 0)

When the plugin is freed the timer callback still gets called and there is an access violation.

I fixed this by stopping the timer in the destructor of VSTPluginInstance:

    const ScopedLock sl (lock);
	stopTimer() //Added by Nikolai 22.06.16
    if (effect != nullptr && effect->magic == kEffectMagic)
       #if JUCE_MAC
        if (module->resFileId != 0)
            UseResFile (module->resFileId);

        // Must delete any editors before deleting the plugin instance!
        jassert (getActiveEditor() == 0);

        _fpreset(); // some dodgy plugs fuck around with this

        module->closeEffect (effect);

    module = nullptr;
    effect = nullptr;

This fixes the crash for me.
Am I on to something ?

OK this is fixed on the develop branch.

1 Like

Thank you fabian