StandaloneFilterWindow AudioSettingsDialog memory leak


#1

Howdy

I'm trying to properly shutdown an app based on the standalonefilterwindow.

For the most part, all is well, however a particular problem is when I have the audio settings window open, and quit the app, it triggers this:

// doh! If you don't delete all your windows before exiting, you're going to
// be leaking memory!
jassert (desktopComponents.size() == 0);

I think I get what is happening here - I'm creating that audio settings window but then not clearing it out properly cause the function that creates it is still running when the application is quit.

What is the best way to close out that audio settings dialog? I'm figuring I will do it in deleteFilter of standalonefilterwindow, but I can't figure out exactly how to do it.

For reference, here is the audio settings creation code:

virtual void showAudioSettingsDialog()
    {
        DialogWindow::LaunchOptions o;
        o.content.setOwned (new AudioDeviceSelectorComponent (*deviceManager,
                                                              filter->getNumInputChannels(),
                                                              filter->getNumInputChannels(),
                                                              filter->getNumOutputChannels(),
                                                              filter->getNumOutputChannels(),
                                                              true, true, false, false));
        o.content->setSize (500, 450);

        o.dialogTitle                   = TRANS("Audio Settings");
        o.dialogBackgroundColour        = Colours::lightgrey;
        o.escapeKeyTriggersCloseButton  = true;
        o.useNativeTitleBar             = true;
        o.resizable                     = false;

        o.launchAsync();
    }

My first guess was to declare DialogWindow::LaunchOptions o; as a private variable of the filterwindow itself - then I could call something like o.content->removeFromDesktop() in the deleteFilter function.

I keep hitting different errors whenever I try things like that, and this is an area of c++ I'm fairly new to. I'm also looking at the OptionalScopePointer part of this (http://www.juce.com/api/structDialogWindow_1_1LaunchOptions.html#afb8d6fb02aec1a20e787de456556067a) - but not quite sure how to implement that.

Thanks for any pointers or areas I could research more on.


#2

I have now realised that deleteFilter is not where to do this, I need to do it in the standalonefilterwindow destructor, probably before deletefilter is called.


#3

FWIW - this happens in the Plugin Host as well.

 

I am going through trying different things...

This thread has some neat ideas, but I'm not sure what he means by 'unwrapped DialogWindow:showDialog()'.

http://www.juce.com/forum/topic/how-avoid-jassert-dialogwindow-app-termination


#4

Got it.

Added this to the scope of standalonefilterwindow:

ScopedPointer<DialogWindow> settingsDialog;

...then set the window to that in showAudioSettingsDialog()

settingsDialog = o.launchAsync();

I was going to try to quickly fix the Plugin Host, but looks like I need to look into the differences between launchAsync and runModal a little more.

 

Thank yall


#5

In MainHostWindow.h

private:
...
    ScopedPointer <DialogWindow> audioSettingsDialog;
...

In MainHostWindow.cpp

void MainHostWindow::showAudioSettings()
{

    DialogWindow::LaunchOptions o;
    o.content.setOwned (new AudioDeviceSelectorComponent(deviceManager,
                                                         0, 256,
                                                         0, 256,
                                                         true, true, true, false));
    o.content->setSize (500, 450);
...

    audioSettingsDialog = o.launchAsync();

...

}

That is all hacked together though by comparing with Standalongfilterwindow - if it is incorrect, please let me know, and of course, use at your own risk.

Thanks yall.


#6

Ok actually - once I change any settings in the AudioSettingsDialog, I'm getting errors on quit, mostly due to scopedpointers or changelisteners related to the audiosettings. I also noticed it gives me errors when I quit after closing the settings dialog.

 

Would appreciate any pointers to what I might be fundamentally getting wrong.

Thanks


#7

bump. how are you supposed to remove modal windows such as the audio settings when the app quits with the window open?

thanks


#8

You could use DeletedAtShutdown, though it's best to have them explicitly deleted by your own components so that everything closes down in the correct order.