[nautilus/wip/corey/focus-crash: 24/24] list-base: Check if item_widget is ready before setting focus
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/corey/focus-crash: 24/24] list-base: Check if item_widget is ready before setting focus
- Date: Thu, 1 Sep 2022 22:33:50 +0000 (UTC)
commit 5ca19601320677eb2807a3abbc825e97899f97a0
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 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))
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]