Quit a Juce app right after start


#1

What is the best way to quit a JUCE app in certain conditions right after starting it? Like based on commandLine parameters in the initialise() method?

I’ve tried to call quit() from the JUCEApplication::initialise() override, but it leaks “2 instance(s) of class WaitableEvent” so I guess it’s not the right way.

Thanks in advance for any suggestions!


#2

Yes, just call quit() and return from the initialise method - you’ll see this done in things like that Projucer. If there’s a leak, it’s probably something you’re doing.


#3

Thanks, you are right it’s “mainWindow = new MainWindow (*this, getApplicationName());” that causes the leak even if right after that I set it to nullptr and call quite(). But if I don’t create the MainWindow then it quits perfectly.


#4

Are you doing anything exciting in the constructor of MainWindow?

After creating a new GUI project from the Producer the following code doesn’t produce any leaks.

void initialise (const String& commandLine) override
{
    // This method is where you should put your application's initialisation code..

    mainWindow = new MainWindow (getApplicationName());
    mainWindow = nullptr;
    quit();
}

#5

Maybe the too obvious question: is your Mainwindow* a raw pointer or a ScopedPointer? I know, the question might sound like “is the power plugged in?”


#6

Definitely will look into that later today. Actually it’s a complex program so there is a lot happening everywhere, but there is no leak if I quit normally, only if I quit from the initialise method after creating the MainWindow. Will check it asap.

And the mainWindow is ScopedPointer (it’s the default Juce made for the project).


#7

This is a freshly created Audio Project (v4.2.3). I just added those 2 lines in the code and as you can see it’s leaking. If I quit normally then there are no leaks, only if I quit from the Init method.


#8

Those aren’t leaks of JUCE objects, that’s the MSVC leak detector, not the JUCE one.

And you will occasionally see a few bytes on there which represents objects that were posted to the message queue, but didn’t get chance to be delivered and deleted before the message queue was killed on shutdown.

TL;DR: Don’t worry about it, get on with your life.


#9

Thanks for clarifying it. My other, more complex project leaks “2 instance(s) of class WaitableEvent” (it’s the JUCE leak detector) when I do the same Quit() from Initialise(). There is no leak for those when I quit the program normally. Can these be connected to the same messaging problem, or that will be unrelated?


#10

Probably unrelated, there won’t be any WaitableEvents inside message data.