GtkTreeView assertion fails:



I trying to figure out why my application fails with:


jukeboxclient (pid:31411): Gtk-ERROR **: file gtkrbtree.c: line 836
(_gtk_rbtree_node_find_offset): assertion failed: (node)
aborting...
Trace/breakpoint trap

Here is an simple testapplication that fails the same way:

I don't know if I am doing wrong or if it is a TreeView bug

but try this:

first expand "AlbumA" and select the first child item "songname 1" and then
again select "songname 2"

then try to expand "AlbumB" and select any of the childitems and it will
fail
with:


jukeboxclient (pid:31411): Gtk-ERROR **: file gtkrbtree.c: line 836
(_gtk_rbtree_node_find_offset): assertion failed: (node)
aborting...
Trace/breakpoint trap

Any one knows whats wrong???



Greets


-----------------------------------------------------------------------------------

#include <gtk/gtk.h>

int selid=0;
GtkTreeModel *model;
GtkWidget *tree;
gboolean block_expand_again=FALSE;
void onresult();

gboolean
tree_find_albumid(int id, GtkTreeIter *iter)
{
  gchar *txt[1];
  gtk_tree_model_get_iter_root (model, iter);
  do    
    {
      gtk_tree_model_get(model, iter, 0, txt, -1);
     if(id == atoi(txt[0]))  
         return TRUE;

    }  
  while (gtk_tree_model_iter_next(model,iter));

  return FALSE;
}

void
cb_expand(GtkTreeView *view, GtkTreeIter *iter, GtkTreePath *path, gpointer
data)
{
  char *txt[1];

  if (block_expand_again)
    return ;

  gtk_tree_model_get (model, iter, 0, txt, -1);
  selid = atoi(txt[0]);

  onresult();

}

void onresult()
{
  GtkTreeIter piter,iter;
  GtkTreePath *selected;

  if(!tree_find_albumid(selid, &piter))
    return;

  while (gtk_tree_model_iter_children(model, &iter,&piter))
    gtk_tree_store_remove(GTK_TREE_STORE(model), &iter);

  if(!tree_find_albumid(selid, &piter))
    return;

  gtk_tree_store_append(GTK_TREE_STORE(model), &iter, &piter);
  gtk_tree_store_set(GTK_TREE_STORE(model),&iter, 0,"1", 1, "songname 1",
-1);

  gtk_tree_store_append(GTK_TREE_STORE(model), &iter, &piter);
  gtk_tree_store_set(GTK_TREE_STORE(model),&iter, 0,"2", 1, "songname 2",
-1);

  selected=gtk_tree_model_get_path(model,&piter);
  block_expand_again=TRUE;
  gtk_tree_view_expand_row(GTK_TREE_VIEW(tree), selected, 0);
  block_expand_again=FALSE;
}


int
main (int argc, char *argv[])
{
  GtkWidget *widget;
  GtkCellRenderer *cell;
  GtkTreeViewColumn *column;
  GtkTreeIter iter,piter;
  
  gtk_init(&argc, &argv);
  
  widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  model=gtk_tree_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
  tree=gtk_tree_view_new_with_model(model);

  cell = gtk_cell_renderer_text_new();
  column = gtk_tree_view_column_new_with_attributes ("ID", cell, "text",0,
NULL);
  gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column);

  column = gtk_tree_view_column_new_with_attributes ("Artist/Group", cell,
"text", 1, NULL);
  gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column);

  column = gtk_tree_view_column_new_with_attributes ("Songtitle", cell,
"text", 2, NULL);
  gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column);

  gtk_container_add(GTK_CONTAINER(widget), tree);
  gtk_signal_connect(GTK_OBJECT(widget), "destroy",
GTK_SIGNAL_FUNC(gtk_main_quit), NULL);

  gtk_tree_store_append(GTK_TREE_STORE(model), &iter, NULL);
  gtk_tree_store_set(GTK_TREE_STORE(model),&iter, 0,"1", -1);
  gtk_tree_store_set(GTK_TREE_STORE(model),&iter, 1,"ArtistA", -1);

  piter=iter;
  gtk_tree_store_append(GTK_TREE_STORE(model), &iter, &piter);
  gtk_tree_store_set(GTK_TREE_STORE(model),&iter, 0,"0", -1);
  gtk_tree_store_set(GTK_TREE_STORE(model),&iter, 1,"Please wait...", -1);

  gtk_tree_store_append(GTK_TREE_STORE(model), &iter, NULL);
  gtk_tree_store_set(GTK_TREE_STORE(model),&iter, 0,"2", -1);
  gtk_tree_store_set(GTK_TREE_STORE(model),&iter, 1,"ArtistB", -1);

  piter=iter;
  gtk_tree_store_append(GTK_TREE_STORE(model), &iter, &piter);
  gtk_tree_store_set(GTK_TREE_STORE(model),&iter, 0,"0", -1);
  gtk_tree_store_set(GTK_TREE_STORE(model),&iter, 1,"Please wait...", -1);

  gtk_tree_store_append(GTK_TREE_STORE(model), &iter, NULL);
  gtk_tree_store_set(GTK_TREE_STORE(model),&iter, 0,"3", -1);
  gtk_tree_store_set(GTK_TREE_STORE(model),&iter, 1,"ArtistC", -1);

  piter=iter;
  gtk_tree_store_append(GTK_TREE_STORE(model), &iter, &piter);
  gtk_tree_store_set(GTK_TREE_STORE(model),&iter, 0,"0", -1);
  gtk_tree_store_set(GTK_TREE_STORE(model),&iter, 1,"Please wait...", -1);


  gtk_signal_connect(GTK_OBJECT(tree), "row_expanded",
GTK_SIGNAL_FUNC(cb_expand), NULL);

  gtk_widget_show_all(widget);  

  gtk_main();
}

M.H.




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