VST Host Crash on Quit


#1

Hello,

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.

Thanks!


#2

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


#3

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:

“MainHostWindow.cpp”:

 void MainHostWindow::closeButtonPressed()
 {
	tryToQuitApplication();
}

 bool MainHostWindow::tryToQuitApplication()
 {
 	JUCEApplication::getInstance()->systemRequestedQuit();
 	return true;
 }

Command-q:

“juce_mac_MessageManager.mm”:

    static NSApplicationTerminateReply applicationShouldTerminate (id /*self*/, SEL, NSApplication*)
    {
        if (JUCEApplicationBase* const app = JUCEApplicationBase::getInstance())
        {
            app->systemRequestedQuit();

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

        return NSTerminateNow;
    }

    static void applicationWillTerminate (id /*self*/, SEL, NSNotification*)
    {
        JUCEApplicationBase::appWillTerminateByForce();
    }

#4

Hmm try running your app in the address sanitiser:

http://images.google.de/imgres?imgurl=http%3A%2F%2Fmeandmark.com%2Fblog%2Fwp-content%2Fuploads%2F2015%2F09%2FSchemeAddressSanitizer.png&imgrefurl=http%3A%2F%2Fmeandmark.com%2Fblog%2F2015%2F09%2Fxcode-7-address-sanitizer%2F&h=347&w=600&tbnid=E4EkQERlKBNatM%3A&docid=9LkuwVZhTH3BZM&ei=RkSKV_K2EuuLgAbb4ITgCw&tbm=isch&iact=rc&uact=3&dur=324&page=1&start=0&ndsp=22&ved=0ahUKEwjy8abCmPjNAhXrBcAKHVswAbwQMwgiKAIwAg&bih=782&biw=1394


#5

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.