From 7cca44976a84388041736a82b3dd0c39e319db2f Mon Sep 17 00:00:00 2001 From: Andre Herbst Date: Fri, 29 Nov 2024 20:10:00 +0100 Subject: [PATCH] fix: prevent segfault in status_handler when downloading a game in grid view Issue: #686 --- src/ui/views/GamesView/grid/GameCard.vala | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/ui/views/GamesView/grid/GameCard.vala b/src/ui/views/GamesView/grid/GameCard.vala index 5a1c21bc..d137ddbb 100644 --- a/src/ui/views/GamesView/grid/GameCard.vala +++ b/src/ui/views/GamesView/grid/GameCard.vala @@ -386,7 +386,14 @@ namespace GameHub.UI.Views.GamesView.Grid private void status_handler(Game.Status s) { + // Use weak reference to avoid capturing `this` strongly + weak GameCard weak_self = this; + Idle.add(() => { + // early return when GameCard got destructed to prevent segfault + if (weak_self == null) + return Source.REMOVE; + label.label = game.name; status_label.label = s.description; favorite_icon.visible = game.has_tag(Tables.Tags.BUILTIN_FAVORITES);