mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:17:45 +00:00
LibGUI: Fix GDirectoryModel lifetime bug.
Thumbnail generation callbacks were getting called after the class was already being destroyed causing a crash to occur.
This commit is contained in:
parent
9da121f837
commit
17597f4681
2 changed files with 9 additions and 2 deletions
|
@ -126,14 +126,20 @@ bool GDirectoryModel::fetch_thumbnail_for(const Entry& entry)
|
||||||
s_thumbnail_cache.set(path, nullptr);
|
s_thumbnail_cache.set(path, nullptr);
|
||||||
m_thumbnail_progress_total++;
|
m_thumbnail_progress_total++;
|
||||||
|
|
||||||
|
auto directory_model = make_weak_ptr();
|
||||||
|
|
||||||
LibThread::BackgroundAction<RefPtr<GraphicsBitmap>>::create(
|
LibThread::BackgroundAction<RefPtr<GraphicsBitmap>>::create(
|
||||||
[path] {
|
[path] {
|
||||||
return render_thumbnail(path);
|
return render_thumbnail(path);
|
||||||
},
|
},
|
||||||
|
|
||||||
[this, path](auto thumbnail) {
|
[this, path, directory_model](auto thumbnail) {
|
||||||
s_thumbnail_cache.set(path, move(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++;
|
m_thumbnail_progress++;
|
||||||
if (on_thumbnail_progress)
|
if (on_thumbnail_progress)
|
||||||
on_thumbnail_progress(m_thumbnail_progress, m_thumbnail_progress_total);
|
on_thumbnail_progress(m_thumbnail_progress, m_thumbnail_progress_total);
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
#include <LibGUI/GModel.h>
|
#include <LibGUI/GModel.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
class GDirectoryModel final : public GModel {
|
class GDirectoryModel final : public GModel
|
||||||
|
, public Weakable<GDirectoryModel> {
|
||||||
public:
|
public:
|
||||||
static NonnullRefPtr<GDirectoryModel> create() { return adopt(*new GDirectoryModel); }
|
static NonnullRefPtr<GDirectoryModel> create() { return adopt(*new GDirectoryModel); }
|
||||||
virtual ~GDirectoryModel() override;
|
virtual ~GDirectoryModel() override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue