From dd1e76e601bb43a083e6b774e7862110f22ee74a Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sun, 19 Mar 2023 17:30:18 +0100 Subject: [PATCH] treelistmodel: Clear item in right place 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 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gtk/gtktreelistmodel.c b/gtk/gtktreelistmodel.c index 8a189fe2ce..dd3b3009cc 100644 --- a/gtk/gtktreelistmodel.c +++ b/gtk/gtktreelistmodel.c @@ -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)); }