# How to avoid jassert() on DialogWindow app termination?

**URL:** <https://forum.juce.com/t/how-to-avoid-jassert-on-dialogwindow-app-termination/9404>\
**Category:** General JUCE discussion\
**Created:** [October 15, 2012, 11:09pm UTC](https://forum.juce.com/t/how-to-avoid-jassert-on-dialogwindow-app-termination/9404 "2012-10-15T23:09:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkoutavas](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jkoutavas/32/147_2.png) [@jkoutavas](https://forum.juce.com/u/jkoutavas)\
**Post date:** [October 15, 2012, 11:09pm UTC](https://forum.juce.com/t/how-to-avoid-jassert-on-dialogwindow-app-termination/9404/1 "2012-10-15T23:09:12Z")

</div>

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().

```auto
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?

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

Is that the accepted way of avoiding the assert?

I’m on JUCE 2.0.27.

---

<div class="post-metadata">

**Author:** ![jkoutavas](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jkoutavas/32/147_2.png) [@jkoutavas](https://forum.juce.com/u/jkoutavas)\
**Post date:** [October 15, 2012, 11:32pm UTC](https://forum.juce.com/t/how-to-avoid-jassert-on-dialogwindow-app-termination/9404/2 "2012-10-15T23:32:11Z")

</div>

My solution:

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

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

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [October 16, 2012, 7:28am UTC](https://forum.juce.com/t/how-to-avoid-jassert-on-dialogwindow-app-termination/9404/3 "2012-10-16T07:28:38Z")

</div>

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.
