1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

FileChooser: Avoid throwing bad_weak_ptr

It seems like shared_from_this may not be enabled when a unique_ptr is
assigned to a shared_ptr (although it *should* be enabled when
constructing a new shared_ptr from a unique_ptr). Functions that return
objects that may need to use shared_from_this now return shared_ptr,
just to be safe.

Additionally, in some cases, shared_from_this was being called from
Thread::run after the last reference to the shared object had been
released. We now call shared_from_this during 'open', which will always
run on the message thread while at least once reference to the shared
object is alive.
This commit is contained in:
reuk 2021-03-03 19:21:41 +00:00
parent 1ff7fc38b1
commit fd2f866dd1
7 changed files with 19 additions and 16 deletions

View file

@ -184,7 +184,7 @@ void FileChooser::launchAsync (int flags, std::function<void (const FileChooser&
}
std::unique_ptr<FileChooser::Pimpl> FileChooser::createPimpl (int flags, FilePreviewComponent* previewComp)
std::shared_ptr<FileChooser::Pimpl> FileChooser::createPimpl (int flags, FilePreviewComponent* previewComp)
{
results.clear();

View file

@ -328,8 +328,8 @@ private:
std::shared_ptr<Pimpl> pimpl;
//==============================================================================
std::unique_ptr<Pimpl> createPimpl (int, FilePreviewComponent*);
static std::unique_ptr<Pimpl> showPlatformDialog (FileChooser&, int, FilePreviewComponent*);
std::shared_ptr<Pimpl> createPimpl (int, FilePreviewComponent*);
static std::shared_ptr<Pimpl> showPlatformDialog (FileChooser&, int, FilePreviewComponent*);
class NonNative;
friend class NonNative;