diff options
author | Brandon Scott <xeons@users.noreply.github.com> | 2019-10-01 20:49:10 -0500 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-10-03 08:17:41 +0200 |
commit | 17597f4681fb7d4e200a021092a351645003f394 (patch) | |
tree | 0955c56324ec22f635c9aced2bfabb5affb6fa1a /Libraries | |
parent | 9da121f837df827b639b7c2e227d05556c4f6a68 (diff) | |
download | serenity-17597f4681fb7d4e200a021092a351645003f394.zip |
LibGUI: Fix GDirectoryModel lifetime bug.
Thumbnail generation callbacks were getting called after the class was already being destroyed causing a crash to occur.
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibGUI/GDirectoryModel.cpp | 8 | ||||
-rw-r--r-- | Libraries/LibGUI/GDirectoryModel.h | 3 |
2 files changed, 9 insertions, 2 deletions
diff --git a/Libraries/LibGUI/GDirectoryModel.cpp b/Libraries/LibGUI/GDirectoryModel.cpp index 21955a03c5..20c80c4c0f 100644 --- a/Libraries/LibGUI/GDirectoryModel.cpp +++ b/Libraries/LibGUI/GDirectoryModel.cpp @@ -126,14 +126,20 @@ bool GDirectoryModel::fetch_thumbnail_for(const Entry& entry) s_thumbnail_cache.set(path, nullptr); m_thumbnail_progress_total++; + auto directory_model = make_weak_ptr(); + LibThread::BackgroundAction<RefPtr<GraphicsBitmap>>::create( [path] { return render_thumbnail(path); }, - [this, path](auto thumbnail) { + [this, path, directory_model](auto thumbnail) { s_thumbnail_cache.set(path, move(thumbnail)); + // class was destroyed, no need to update progress or call any event handlers. + if (directory_model.is_null()) + return; + m_thumbnail_progress++; if (on_thumbnail_progress) on_thumbnail_progress(m_thumbnail_progress, m_thumbnail_progress_total); diff --git a/Libraries/LibGUI/GDirectoryModel.h b/Libraries/LibGUI/GDirectoryModel.h index 5f7ac03049..3a94e5ff2e 100644 --- a/Libraries/LibGUI/GDirectoryModel.h +++ b/Libraries/LibGUI/GDirectoryModel.h @@ -5,7 +5,8 @@ #include <LibGUI/GModel.h> #include <sys/stat.h> -class GDirectoryModel final : public GModel { +class GDirectoryModel final : public GModel + , public Weakable<GDirectoryModel> { public: static NonnullRefPtr<GDirectoryModel> create() { return adopt(*new GDirectoryModel); } virtual ~GDirectoryModel() override; |