mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 23:28:12 +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);
|
||||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue