insaniac has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks!

It's been quite a while since I have asked something, but currently I am in the need of some wisdom again.

I have a Gtk/Perl application, which lists hostnames and when I click on a hostname, it opens a terminal with a SSH session to that host, and searches the root password in GPG encrypted file and saves it in the clipboard for about 60 seconds. That all works well.

Now, when I search the list (by simply typing in the application or using CTRL+F) and when it returns a selection made by the search, if I then use the arrows keys (up or down) to move along in the selection list, it crashes.

During the searches, I get the following warnings:

Gtk-CRITICAL **: gtk_tree_store_get_path: assertion 'iter->stamp == tr +ee_store->stamp' failed at 0PS_Terminal line 149.
(Line 149 is just the Gtk2->main)

If I use an arrow key, it crashes with Segmentation fault

The search is controlled by:

$tree_view->set_search_equal_func(sub { # reset to the main tree store, containing all the hosts $tree_view->set_model($tree_store); my ($_tree_store, $path, $pattern, $iter) = @_; return unless length($pattern) > 2; my %results; $_tree_store->foreach(sub { my ($model, $path, $iter) = @_ ; my $host = $model->get($iter, 0); my $ip = $model->get($iter, 1); if($host =~ /$pattern/){ # print "Found $host for $pattern\n"; $results{$host} = $ip; } # return 0, so that the function always iterates throu +gh # the entire tree store return 0 }); # build the new tree store and display in the tree view if(scalar keys %results > 0){ my $new_treestore = create_treestore(\%results); $tree_view->set_model($new_treestore); # $tree_view->set_cursor(0); $tree_view->set_search_column(0); # my $iter = $new_treestore->get_first_iter(); my $path = $new_treestore->get_path( $new_treestore->g +et_iter_first() ); $tree_view->set_cursor($path); undef $path; #get the Gtk2::TreeSelection of $tree_view my $treeselection = $tree_view->get_selection; #set its initial mode $treeselection->set_mode('single'); } }, undef);
The sub create_treestore looks like this:
sub create_treestore { my ($data) = @_; my ($tree_store) = Gtk2::TreeStore->new(qw/Glib::String Glib::Stri +ng Glib::String/); my $count = 0; foreach my $host (sort keys %{$data}){ my $iter_child = $tree_store->append(undef); my ($dc) = ($host =~ /^(.+?)-/); my $ip = lookup_host_in_hostlistdb($host); my $background = get_background($dc); $tree_store->set($iter_child, 0, $host, 1, $ip, 2, ($count++ % 2 ? $background-> +[1]:$background->[0]), ); } return $tree_store; }

What am I doing wrong? Any idea / hint would be extremely helpful!

Thanks!

UPDATE:It only happens when the search input field is there. If I hit ESC after the search, the search input field disappears and then I can use the arrow keys to move along the selection list.

to ask a question is a moment of shame
to remain ignorant is a lifelong shame

Replies are listed 'Best First'.
Re: Gtk2::TreeStore problem ( gtk_tree_store_get_path: assertion 'iter->stamp == tree_store->stamp' )
by Anonymous Monk on Mar 26, 2015 at 09:50 UTC

    What am I doing wrong? Any idea / hint would be extremely helpful!

    Lets look at the error

    gtk_tree_store_get_path: assertion 'iter->stamp == tree_store->stamp' failed

    So we're dealing with an "get_path" and "iter" and a "store"

    So in your code my ($_tree_store, $path, $pattern, $iter) = @_; ...

    And you have

    my $path = $new_treestore->get_path( $new_treestore->get_iter_first() +);

    Next step would be look up the documentation for gtk_tree_store_get_path and look for examples to see what it wants (its clearly not get_iter_first() )

    Maybe check your Gtk...versions against bug reports regarding this