System::unloadPlugin failed

Hello. I’m having a problem with unloading VST plugin. How do I correctly unload it and when should I call unloadPlugin()? My current code is:


unloadPlugin() returns an error:

If that is the only place that the DSP is being used, then you may have to put a sleep loop in until it has actually been removed from the channel that is using it.

I waited almost a minute and it still has not been removed.
I’m doing something wrong, maybe I’m calling functions in the wrong order.
By the way, this DSP is installed on the master channel (master group), does it change anything?

Being on the master group should not change anything.

Removing the DSP shouldn’t be an issue, releasing the DSP is the thing that can take some time. This is one way that you could handle it:

result = masterGroup->removeDSP(dsp);
result = dsp->release();
    result = system->update(); /* Process the DSP queue */
    result = system->unloadPlugin(pluginHandle);
} while (result == FMOD_ERR_DSP_INUSE);

Oh, I totally forgot about update(). Thanks!