Do TreeIters persist after foreach search ?

I'm trying to write a method that locates a particular node in a
Gtk2::TreeStore. I'm using the foreach method as the basis for walking
the tree to find the node, but I'm having trouble extracting the
resulting iter. I get errors like this:

  Gtk-CRITICAL **: gtk_tree_store_get_value: assertion `iter->stamp ==
GTK_TREE_STORE (tree_model)->stamp' failed

I think there must be something I'm overlooking about iters. I have code
which for testing I've simplified to the following:

    my $match_iter;
        sub {
            my ($tree_store, $path, $iter) = @_;

            my $level = $tree_store->get($iter, LEVEL);
            warn "  tree_store=$tree_store, iter=$iter;\n";

            $match_iter = $iter;
            return TRUE;

    warn "search $tree_store => $match_iter;\n";
    my $level = $tree_store->get($match_iter, LEVEL);

It prints

  search Gtk2::TreeStore=HASH(0x8283970) =>
  Gtk-CRITICAL **: gtk_tree_store_get_value: assertion `iter->stamp ==
GTK_TREE_STORE (tree_model)->stamp' failed at [[[ the second get ]]]

So the tree_store and the iter values seem to be the same but somehow
the stamp is different and I can't see why.

The gtk+ docs mention complications about the lifetime of iters but (a)
I don't think what I'm doing causes the model to emit any signals and
(b) the GtkTreeModelFlags include 'iters-persist' when I print them. The
docs say "Additionally, some models guarantee that an iterator is valid
for as long as the node it refers to is valid (most notably the
GtkTreeStore ..."

Any ideas what's happening, or better ways to find a node in the model?

Cheers, Dave

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