0

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.

Shafa95
  • 201
  • 2
  • 14
  • You don't seem to have any syncronization. What happens if one function is executed multiple times or both execute at the same time? – nvoigt Jun 01 '14 at 14:18
  • I know I haven't implemented any synchronization. Could you explain how to do it? I've never had to deal with these problems. thank you very much – Shafa95 Jun 01 '14 at 14:32
  • I solved the problem by using properly the `lock` keyword. Thanks for making me understand the origin of the problem. – Shafa95 Jun 01 '14 at 18:01

0 Answers0