[gtk+] inspector: Reset the treewalk when required
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] inspector: Reset the treewalk when required
- Date: Fri, 11 Mar 2016 18:54:18 +0000 (UTC)
commit 5e68c4e62dedbdbf620ae4d016ac38cb1732a5e3
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Mar 11 13:52:36 2016 -0500
inspector: Reset the treewalk when required
The tree walk holds a tree iter, which will become invalid
when we either remove the row that it points to or remove
all rows.
Reset the tree walk in those cases to avoid a crash that
was pointed out by Bastien Nocera.
gtk/inspector/object-tree.c | 31 +++++++++++++++++++++++++++----
1 files changed, 27 insertions(+), 4 deletions(-)
---
diff --git a/gtk/inspector/object-tree.c b/gtk/inspector/object-tree.c
index 0757b97..18c08a4 100644
--- a/gtk/inspector/object-tree.c
+++ b/gtk/inspector/object-tree.c
@@ -610,20 +610,31 @@ on_selection_changed (GtkTreeSelection *selection,
g_signal_emit (wt, signals[OBJECT_SELECTED], 0, object);
}
+typedef struct {
+ GObject *dead_object;
+ GtkTreeWalk *walk;
+ GtkTreePath *walk_pos;
+} RemoveData;
+
static gboolean
remove_cb (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data)
{
- GObject *dead_object = data;
+ RemoveData *remove_data = data;
GObject *lookup;
gtk_tree_model_get (model, iter, OBJECT, &lookup, -1);
- if (lookup == dead_object)
+ if (lookup == remove_data->dead_object)
{
+ if (remove_data->walk_pos != NULL &&
+ gtk_tree_path_compare (path, remove_data->walk_pos) == 0)
+ gtk_tree_walk_reset (remove_data->walk, NULL);
+
gtk_tree_store_remove (GTK_TREE_STORE (model), iter);
+
return TRUE;
}
@@ -634,8 +645,20 @@ static void
gtk_object_tree_remove_dead_object (gpointer data, GObject *dead_object)
{
GtkInspectorObjectTree *wt = data;
+ GtkTreeIter iter;
+ RemoveData remove_data;
- gtk_tree_model_foreach (GTK_TREE_MODEL (wt->priv->model), remove_cb, dead_object);
+ remove_data.dead_object = dead_object;
+ remove_data.walk = wt->priv->walk;
+ if (gtk_tree_walk_get_position (wt->priv->walk, &iter))
+ remove_data.walk_pos = gtk_tree_model_get_path (GTK_TREE_MODEL (wt->priv->model), &iter);
+ else
+ remove_data.walk_pos = NULL;
+
+ gtk_tree_model_foreach (GTK_TREE_MODEL (wt->priv->model), remove_cb, &remove_data);
+
+ if (remove_data.walk_pos)
+ gtk_tree_path_free (remove_data.walk_pos);
}
static gboolean
@@ -661,6 +684,7 @@ clear_store (GtkInspectorObjectTree *wt)
{
gtk_tree_model_foreach (GTK_TREE_MODEL (wt->priv->model), weak_unref_cb, wt);
gtk_tree_store_clear (wt->priv->model);
+ gtk_tree_walk_reset (wt->priv->walk, NULL);
}
}
@@ -679,7 +703,6 @@ map_or_unmap (GSignalInvocationHint *ihint,
gtk_tree_store_set (wt->priv->model, &iter,
SENSITIVE, gtk_widget_get_mapped (widget),
-1);
-
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]