1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-22 01:34:21 +00:00

FileChooser: Avoid crash when destroying an open non-native filechooser

This commit is contained in:
reuk 2022-01-31 12:31:40 +00:00
parent 0f06f45098
commit 793f1bf2ee

View file

@ -27,7 +27,8 @@ namespace juce
{
//==============================================================================
class FileChooser::NonNative : public FileChooser::Pimpl
class FileChooser::NonNative : public std::enable_shared_from_this<NonNative>,
public FileChooser::Pimpl
{
public:
NonNative (FileChooser& fileChooser, int flags, FilePreviewComponent* preview)
@ -50,7 +51,15 @@ public:
void launch() override
{
dialogBox.centreWithDefaultSize (nullptr);
dialogBox.enterModalState (true, ModalCallbackFunction::create ([this] (int r) { modalStateFinished (r); }), true);
const std::weak_ptr<NonNative> ref (shared_from_this());
auto* callback = ModalCallbackFunction::create ([ref] (int r)
{
if (auto locked = ref.lock())
locked->modalStateFinished (r);
});
dialogBox.enterModalState (true, callback, true);
}
void runModally() override