FileChooser on stack vs launchAsync

What is roughly the difference between using FileChooser on stack vs using launchAsync mechanism?
Is the main event loop stalled while a modal is on screen?
It is rather new for me, and it doesn’t appears to be obvious while quickly reading the sources.

Putting it on the stack will start a new event loop at the beginning of the call. Although this is convenient, it can cause issues in plugins, as important messages (like quit) will now be processed inside the plugin, rather than from the host’s main event loop. This can result in unexpected behaviour, including crashes.

launchAsync doesn’t suffer from this problem, and it should be preferred in new projects.

1 Like

launchAsync doesn’t suffer from this problem, and it should be preferred in new projects.

That was i thought but the documentation and tutorials mostly use the other.

Putting it on the stack will start a new event loop at the beginning of the call.

That means that launchAsync doesn’t, and lets the main loop handles events?

Yes, we need to spend some time updating these. In a future release of JUCE, we’re considering disabling modal loops altogether in new projects (although we’ll still allow them to be enabled with a switch), so we’ll definitely update the examples/docs at that point, if not before.

Yes, exactly.

2 Likes