mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 03:55:24 +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
Notes:
sideshowbarker
2024-07-19 11:51:12 +09:00
Author: https://github.com/xeons Commit: https://github.com/SerenityOS/serenity/commit/17597f4681f Pull-request: https://github.com/SerenityOS/serenity/pull/622 Reviewed-by: https://github.com/awesomekling
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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue