diff options
author | Corey Berla <corey@berla.me> | 2022-09-01 09:24:49 -0700 |
---|---|---|
committer | António Fernandes <antoniof@gnome.org> | 2022-09-01 22:33:49 +0000 |
commit | 5ca19601320677eb2807a3abbc825e97899f97a0 (patch) | |
tree | 078a5a97f5a75a866de4248d6d9a412e45cc4aed | |
parent | 683a3d54ef2e884a0abf812f35df7751ce0f509e (diff) | |
download | nautilus-5ca19601320677eb2807a3abbc825e97899f97a0.tar.gz |
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
-rw-r--r-- | src/nautilus-list-base.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/nautilus-list-base.c b/src/nautilus-list-base.c index 3784c6a2f..52f9f6560 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)) { |