# FileChooser launchAsync crashs

**URL:** <https://forum.juce.com/t/filechooser-launchasync-crashs/49925>\
**Category:** MacOSX and iOS\
**Created:** [January 31, 2022, 6:40am UTC](https://forum.juce.com/t/filechooser-launchasync-crashs/49925 "2022-01-31T06:40:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![conTimbre](https://avatars.discourse-cdn.com/v4/letter/c/bc79bd/32.png) [@conTimbre](https://forum.juce.com/u/conTimbre)\
**Post date:** [January 31, 2022, 6:40am UTC](https://forum.juce.com/t/filechooser-launchasync-crashs/49925/1 "2022-01-31T06:40:52Z")

</div>

Hi,

i use Juce 6.1.4 on Mac M1 ARM Mac OS 12.0.1, XCode 13.1.  
I program a simple GUI with a button to choose a directory. The GUI always crashs directly when clicking the button. I don’t know why. Code see below. Thank you for help.

Thomas

* * *

void MainComponent::buttonClicked(juce::Button\* button)  
{  
if (button == &myButton)  
{  
juce::FileChooser fc (“title”,juce::File(),"\*",false);  
int flags = juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectDirectories;  
auto callback = (const juce::FileChooser& fileChooser)  
{  
auto files = fileChooser.getResults();  
};  
fc.launchAsync (flags, callback);  
}  
}

---

<div class="post-metadata">

**Author:** ![nicolasdanet](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nicolasdanet/32/56_2.png) [@nicolasdanet](https://forum.juce.com/u/nicolasdanet)\
**Post date:** [January 31, 2022, 7:01am UTC](https://forum.juce.com/t/filechooser-launchasync-crashs/49925/2 "2022-01-31T07:01:07Z")

</div>

Your `FileChooser` is on the stack, whereas it should be cached somewhere.  
It is destroyed right now at the end of the `buttonClicked` call.  
There’s a simple example into the documentation with a global variable.

[https://docs.juce.com/master/classFileChooser.html](https://docs.juce.com/master/classFileChooser.html)

See Also:

> [@File Chooser async](https://forum.juce.com/t/file-chooser-async/47657):
>
> I’m working on a port to AUv3 and it still has a few problems. One of them is the file chooser. In the AUv3 version on Mac and iOS it dosen’t work at all. And on the standalone-app on iOS it opens a file chooser, but I can’t load files and if I creat and save a file it’s empty. Maybe it has to that it’s not implemented in an async way? if (b == &savePreset){ auto presetManager = processor-\>getPresetManager(); String currentPresetPath = presetManager-\>getCurrentPresetDirectory(…

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [January 31, 2022, 12:32pm UTC](https://forum.juce.com/t/filechooser-launchasync-crashs/49925/3 "2022-01-31T12:32:43Z")

</div>

Thanks for reporting this issue. Although the code you posted won’t work as you expect (as @nicolasdanet pointed out, the FileChooser will go out of scope immediately, closing the dialog), the program shouldn’t crash. The crash is due to a bug in JUCE, and I’ll fix this behaviour shortly.

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [February 8, 2022, 1:43pm UTC](https://forum.juce.com/t/filechooser-launchasync-crashs/49925/4 "2022-02-08T13:43:29Z")

</div>

The crash is now fixed on develop:

> <https://github.com/juce-framework/JUCE/commit/793f1bf2ee7d7df981b6ef38e16b98e63a897db3>
