1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-08 04:20:09 +00:00

FileChooser: Launch chooser asynchronously

When FileChooser instances were created, launched, and hidden all inside
the same event callback on macOS 12.0.1, the chooser dialog sometimes
remained open. This could cause problems including crashes, as closing
the dialog would attempt to call a completion handler block referencing
an already-deleted FileChooser::Native instance.

Opening the chooser panel later on the message thread seems to resolve
the issue.
This commit is contained in:
reuk 2021-11-18 19:34:20 +00:00
parent 8458ac0186
commit da46ee6c7a
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C

View file

@ -82,8 +82,9 @@ public:
filters.trim();
filters.removeEmptyStrings();
NSString* nsTitle = juceStringToNS (owner.title);
auto* nsTitle = juceStringToNS (owner.title);
[panel setTitle: nsTitle];
[panel setReleasedWhenClosed: YES];
JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wdeprecated-declarations")
[panel setAllowedFileTypes: createAllowedTypesArray (filters)];
@ -153,22 +154,14 @@ public:
if (nsViewPreview != nil)
{
[panel setAccessoryView: nil];
[nsViewPreview release];
nsViewPreview = nil;
preview = nullptr;
}
[panel close];
[panel release];
}
if (delegate != nil)
{
[delegate release];
delegate = nil;
}
}
void launch() override
@ -179,10 +172,17 @@ public:
addToDesktop (0);
enterModalState (true);
[panel beginWithCompletionHandler:CreateObjCBlock (this, &Native::finished)];
if (preview != nullptr)
preview->toFront (true);
MessageManager::callAsync ([ref = SafePointer<Native> (this)]
{
if (ref == nullptr)
return;
[ref->panel beginWithCompletionHandler: CreateObjCBlock (ref.getComponent(), &Native::finished)];
if (ref->preview != nullptr)
ref->preview->toFront (true);
});
}
}