Modal dialogs sometimes fail to show


I got a report from someone using xmonad about the juce FileChooserDialog not showing up , and this is something that I could reproduce with the latest juce demo:

 - disable the native file chooser with JUCE_DISABLE_NATIVE_FILECHOOSERS

- start xmonad

- launch the juce demo, select the code editor demo, click on the "..." button to browser for files:

semi-randomly (on my config, it certainly depend on the timing and ordering of events) , the dialogs shows up, or not.


I traced it to the following issue: in Component::enterModalState, you have:


        ModalComponentManager* const mcm = ModalComponentManager::getInstance();
        mcm->startModal (this, deleteWhenDismissed);
        mcm->attachCallback (this, callback);

        flags.currentlyModalFlag = true;
        setVisible (true);

If I trace the calls to ModalComponentManager::ModalItem::componentPeerChanged and ModalItem::componentVisibilityChanged, I get various results -- they can get called in any order before the FileChooser dialog gets displayed, and their component->isShowing() test can return either true or false.

When the last component->isShowing() call returns false, the file chooser dialog is dismissed before it shows up.

The issue is fixed if I move the setVisible(true) call before  the mcm->startModal but I'm not sure if that is a correct fix .




Ok, thanks - changing the order could break user code that expects the component to already be modal when its visibilityChanged method is called, but I'll have a look at what else could be done to avoid that situation.