How to avoid jassert() on DialogWindow app termination?

Quitting a debug targetted JUCE application with a dialog window open created from DialogWindow::showDialog() or DialogWindow::showModalDialog() gives a fatal assert in Desktop::Desktop().

    setScreenSaverEnabled (true);

    jassert (instance == this);
    instance = nullptr;

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

How to avoid this bullet on app quit? Do I need to use the following to grab the dialog window’s pointer and delete it myself?

Dialogwindow* dw = contentComponent->findParentComponentOfClass<DialogWindow>()

Is that the accepted way of avoiding the assert?

I’m on JUCE 2.0.27.

My solution:

I unwrapped DialogWindow::showDialog() into my code space and am keeping the DialogWindow pointer returned by LaunchOptions::launchAsync()

DialogWindow::LaunchOptions o;
myDialog = o.launchAsync();

Yep, avoiding modal loops is a very very good idea. They really are evil.

In the introjucer I also use a trick with a timer on shutdown, where it signals for any modal comps to close, and then delays quitting until they’ve gone.