treelistmodel: Clear item in right place
authorBenjamin Otte <otte@redhat.com>
Sun, 19 Mar 2023 16:30:18 +0000 (17:30 +0100)
committerBenjamin Otte <otte@redhat.com>
Sun, 19 Mar 2023 16:38:38 +0000 (17:38 +0100)
Items should be cleared when the node is discarded, not when the node's
children are discarded - which can also happen when a node is collapsed.

Fixes an error introduced in 9048e391b60e19ccefa0b9fe51c466d16b42dcc4

Fixes #5681

gtk/gtktreelistmodel.c

index 8a189fe2ce1d231ea4a73b20f2a09c01041c31c4..dd3b3009ccc6003d5899cb0d64b0d902a8cf1ca2 100644 (file)
@@ -362,6 +362,7 @@ gtk_tree_list_model_items_changed_cb (GListModel *model,
       child = gtk_rb_tree_insert_before (node->children, child);
       child->parent = node;
       child->item = g_list_model_get_item (model, position + i);
+      g_assert (child->item);
     }
   if (self->autoexpand)
     {
@@ -387,8 +388,6 @@ static void gtk_tree_list_row_destroy (GtkTreeListRow *row);
 static void
 gtk_tree_list_model_clear_node_children (TreeNode *node)
 {
-  g_clear_object (&node->item);
-
   if (node->model)
     {
       g_signal_handlers_disconnect_by_func (node->model,
@@ -409,6 +408,8 @@ gtk_tree_list_model_clear_node (gpointer data)
     gtk_tree_list_row_destroy (node->row);
 
   gtk_tree_list_model_clear_node_children (node);
+
+  g_clear_object (&node->item);
 }
 
 static void
@@ -464,6 +465,7 @@ gtk_tree_list_model_init_node (GtkTreeListModel *list,
       node = gtk_rb_tree_insert_after (self->children, node);
       node->parent = self;
       node->item = g_list_model_get_item (model, i);
+      g_assert (node ->item);
       if (list->autoexpand)
         gtk_tree_list_model_expand_node (list, node);
     }
@@ -945,12 +947,13 @@ gtk_tree_list_row_destroy (GtkTreeListRow *self)
 {
   g_object_freeze_notify (G_OBJECT (self));
 
+  self->node = NULL;
+
   /* FIXME: We could check some properties to avoid excess notifies */
   g_object_notify_by_pspec (G_OBJECT (self), row_properties[ROW_PROP_DEPTH]);
   g_object_notify_by_pspec (G_OBJECT (self), row_properties[ROW_PROP_EXPANDABLE]);
   g_object_notify_by_pspec (G_OBJECT (self), row_properties[ROW_PROP_EXPANDED]);
 
-  self->node = NULL;
   g_object_thaw_notify (G_OBJECT (self));
 }