Alert sound happens when hiding window that was in nested enterModalState()

My project needs to display a DocumentWindow to collect some info from the user.
Said window is displayed and enterModalState() is called on it.

That DocumentWindow in turn may need to display a “nested” DocumentWindow (in the sense that appears in front of it), to collect login credentials. enterModalState() is called on this window as well. The documentation says that it is possible to have multiple levels of modal components.

When the user closes the frontmost credentials window, the code calls exitModalState() and setVisible (false) on it, in this order.

When setVisible (false) is called, an alert “beep” sound is triggered, the one that signals a failed attempt to interact with some other part of the UI when something is modal.

If I comment the setVisible (false), the sound disappears but the frontmost window remains visible, which is not the desired behaviour.

I have attached a Projucer project that demonstrates this.
The screenshot outlines the result:

The window with the native title bar is the main window (not modal) and has no part in the bug.

The two with the “JUCE” title bar are both in enterModalState(), with the frontmost being the one that entered last in the modal state. Closing it will “beep”, while closing the one at the first level will not.

If you create more that two nested windows, all those from the second level on will beep when closing. Only the first doesn’t.

How do I avoid the sound to happen for all the nested ones?

Tested on macOS 10.14 with latest JUCE 5.4.5 on develop branch

Screenshot 2019-12-24 at 11.51.38 (125.6 KB)

While I’ve worked around this issue in the case of my own windows, the very same issue happens with CalloutBox, which upon dismissal does exactly the


that triggers the issue.

To reproduce, see the attachment to my previous post, or open a CalloutBox from a Window that’s already modal. You will get the “beep” as soon as you dismiss the callout

(sorry for the tagging, but I received no response to my original post despite the fact that more than a month has passed: @jules @ed95 @t0m)

The problem I’ve described seem to also affect some other users and classes:

1 Like

This should fix the issue:

1 Like

Yes it does, thank you very much (sorry for the delay)