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:

Channel::removeDSP();
DSP::release();
System::unloadPlugin();

unloadPlugin() returns an error:
image

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);
ERRCHECK(result);
result = dsp->release();
ERRCHECK(result);
do
{
    result = system->update(); /* Process the DSP queue */
    ERRCHECK(result);
    result = system->unloadPlugin(pluginHandle);
} while (result == FMOD_ERR_DSP_INUSE);

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