VST Host Crash on Quit


I have a standalone app that is a vst plugin inside a Juce host. I’m having an issue where my app crashes on exit. I get a EXC_BAD_ACCESS at [NSApp run];

The strange thing though is that this only happens if you quit using the top left ‘x’ button. If you quit with command-q or go to the system menu to quit, there is no crash.

I’ve read that this happens because there are still background processes trying to run that haven’t finished, but I haven’t been able to find a solution and I can’t figure out what is happening with command-q that is not happening with the window close button. They both call the same systemRequestedQuit() method.

I’ve searched for answers and debugged for hours but haven’t made any progress.


Are you maybe deleting the window in the closeButtonPressed method and then deleting it again when your app quits?

It doesn’t seem like that’s happening. Here’s how each method gets to systemRequestedQuit(). Command-q eventually triggers applicationWillTerminate(), but I’m having trouble tracing where the problem occurs for closeButton.

Close button:


 void MainHostWindow::closeButtonPressed()

 bool MainHostWindow::tryToQuitApplication()
 	return true;



    static NSApplicationTerminateReply applicationShouldTerminate (id /*self*/, SEL, NSApplication*)
        if (JUCEApplicationBase* const app = JUCEApplicationBase::getInstance())

            if (! MessageManager::getInstance()->hasStopMessageBeenSent())
                return NSTerminateCancel;

        return NSTerminateNow;

    static void applicationWillTerminate (id /*self*/, SEL, NSNotification*)

Hmm try running your app in the address sanitiser:


Address Sanitizer didn’t show any issues with closeButton quitting even though the crash still occurs. (I was, however, able to locate some other small memory issues in my app and fix them). Any other suggestions? Banging my head on the wall over this one. I can’t seem to make any progress.