Right way to close a plugin's editor window?


#1

Is this right? Its being called from a thread separate from the main message thread.

    static void closeProcessor (AudioProcessor* processor)
    {
      if (processor)
      {
        AudioProcessorEditor* editor = processor->getActiveEditor ();
       
        if (editor)
        {
          const MessageManagerLock mmLock;

          ComponentPeer* peer = editor->getPeer();
          if (peer)
            delete peer;

          delete editor;
        }

        processor->releaseResources ();
      }
    }

#2

If I remember correctly, you should call also editorBeingDeleted (it’s an AudioProcessor’s method).


#3

The right way to close the window is to not close the window.

The host deletes the window, not the plugin. If you delete it yourself, you’ll leave the host with a dangling window handle which could cause a crash, or at best just leave a black empty window.


#4

I am the host! So how do I do it? Is my code right?


#5

Oh sorry, I misunderstood!

Well, definitely do NOT delete it on a background thread. That will seriously fuck-up a lot of plugins, mostly because of win32 windows being owned by the thread that created them.

I can’t remember any other tips, but just do what the plugin host example does…


#6

Hahaha…that worked much better :slight_smile:

Here’s the new code:

    static void* deleteComponent (void* userData)
    {
      Component* comp = static_cast<Component*>(userData);
      Component* top = comp->getTopLevelComponent();
      delete top;
      return 0;
    }

    static void closeProcessor (AudioProcessor* processor)
    {
      if (processor)
      {
        AudioProcessorEditor* editor = processor->getActiveEditor ();
       
        if (editor)
        {
          MessageManager::getInstance()->callFunctionOnMessageThread (
            deleteComponent, editor);
        }

        processor->releaseResources ();
      }
    }