I've implemented a VST host that allows you to use any VST effect by loading a .dll file.
I have a problem with removing of the plugin while running: When I press 'Play' button my ASIO callback function checks if there are active plugins, and if so it triggers a function that converts the sample and passes them to the plugin so that they processes it.
Before it executes the statement plugin.processReplacing() it checks the plugin isn't null, but it's as if this control were ignored.
When I press the 'Stop' or 'Remove Effect' buttons the program turn off the plugin and set it to null, so at this point the statement plugin.processReplacing() should not be performed, instead sometimes it processes it and gives me the error: NullReferenceException.
Maybe I have to wait before the plugin executes the instruction processReplacing() for the last time before turning off the plugin, but I don't know how to do it.
There's some code:
Remove plugin procedure:
public void rimuoviPlugin()
{
if (vstForm != null) vstForm.Close();
if (processor.plugin == null) return;
//Spengo i plugin
processor.plugin.EditorClose();
processor.plugin.StopProcess();
processor.plugin.MainsChanged(false);
processor.plugin.Close();
processor.plugin = null;
}
processSample procedure:
if (plugin != null)
{
plugin.ProcessReplacing(vstBufIn, vstBufOut);
plugin.EditorIdle();
}
Does anyone have any idea to remedy the problem? (If you need other code, just ask me)
Thanks at all.