[nautilus/wip/corey/focus-crash] list-base: Check if item_widget is ready before setting focus




commit 7899b480f43f8fa0d25b27d1004923c8f3ce45f1
Author: Corey Berla <corey berla me>
Date:   Thu Sep 1 09:24:49 2022 -0700

    list-base: Check if item_widget is ready before setting focus
    
    We use a hack to set the focus on the item when we set the selection.
    Sometimes, the item_widget isn't ready by the time we are setting
    the focus, which causes a seg fault.  This became even worse, when
    I applied the focus hack more consistently in 2ac420316bd9c8560fa2cdeba0e5f5b0092243b7
    
    We should find a better solution, but in the meantime, let's stop
    crashing.
    
    Fixes: https://gitlab.gnome.org/GNOME/nautilus/-/issues/2400

 src/nautilus-list-base.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
---
diff --git a/src/nautilus-list-base.c b/src/nautilus-list-base.c
index ab72c6fc0..0a73f1326 100644
--- a/src/nautilus-list-base.c
+++ b/src/nautilus-list-base.c
@@ -245,7 +245,15 @@ set_focus_item (NautilusListBase *self,
 {
     NautilusListBasePrivate *priv = nautilus_list_base_get_instance_private (self);
     GtkWidget *item_widget = nautilus_view_item_get_item_ui (item);
-    GtkWidget *parent = gtk_widget_get_parent (item_widget);
+    GtkWidget *parent;
+
+    if (item_widget == NULL)
+    {
+        /* We can't set the focus if the item isn't created yet. Return early to prevent a crash */
+        return;
+    }
+
+    parent = gtk_widget_get_parent (item_widget);
 
     if (!gtk_widget_grab_focus (parent))
     {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]