[gtk/stack-fixes] stack switcher: Be robust in destruction



commit cb58d08c31572d6082940cc7c57c6e572a48366c
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Feb 9 15:04:33 2019 -0500

    stack switcher: Be robust in destruction
    
    There are various places where we might not find
    a widget, if we are already in destruction when
    a signal comes in. Be robust. This was showing
    up as critical warnings when closing widget-factory.

 gtk/gtkstackswitcher.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkstackswitcher.c b/gtk/gtkstackswitcher.c
index da268fb694..1be3696606 100644
--- a/gtk/gtkstackswitcher.c
+++ b/gtk/gtkstackswitcher.c
@@ -113,7 +113,7 @@ on_button_clicked (GtkWidget        *button,
       guint index;
 
       index = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (button), "child-index"));
-      gtk_selection_model_select_item (GTK_SELECTION_MODEL (priv->pages), index, TRUE);
+      gtk_selection_model_select_item (priv->pages, index, TRUE);
     }
 }
 
@@ -314,7 +314,7 @@ add_child (guint             position,
   gtk_container_add (GTK_CONTAINER (self), button);
 
   g_object_set_data (G_OBJECT (button), "child-index", GUINT_TO_POINTER (position));
-  selected = gtk_selection_model_is_selected (GTK_SELECTION_MODEL (priv->pages), position);
+  selected = gtk_selection_model_is_selected (priv->pages, position);
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), selected);
 
   page = gtk_stack_get_page (GTK_STACK (priv->stack), widget);
@@ -389,9 +389,15 @@ selection_changed_cb (GtkSelectionModel *model,
       gboolean selected;
 
       child = g_list_model_get_item (G_LIST_MODEL (priv->pages), i);
+      if (child == NULL)
+        continue;
+
       button = g_hash_table_lookup (priv->buttons, child);
-      selected = gtk_selection_model_is_selected (GTK_SELECTION_MODEL (priv->pages), i);
-      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), selected);
+      if (button)
+        {
+          selected = gtk_selection_model_is_selected (priv->pages, i);
+          gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), selected);
+        }
       g_object_unref (child);
     }
 


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