GNOME Bugzilla – Bug 498010
gtk_tree_view_set_cursor fails if model!=NULL
Last modified: 2009-07-30 12:03:18 UTC
gtk_tree_view_set_cursor or gtk_tree_view_real_set_cursor should check for tree_view->priv->model!=NULL. Otherwise:
+ Trace 178584
I can't reproduce this crash (?). Tried with: view = gtk.TreeView() view.set_cursor((0, 1, 2)) But I just get the same warning as in your traceback. The traceback also seem to suggest that the crash occurs in gmessages.c and not in gtk.
Its with fatal warnings. Thats way it terminates. Basically I am complaining about that gtk_tree_view_set_cursor() should just return if there is no model and not blindly make furtehr calls.
Oh, now I understand. I don't think it should "just return" but instead check "g_return_if_fail (tree_view->priv->model != NULL);" in the beginning of set_cursor() because that is consistent with scroll_to_cell(), expand_row(), collapse_row() and how other methods that expect the model to be there behaves.
Committed a return if fail ->priv->tree != NULL (if there is no tree, there is no model either) in gtk_tree_view_set_cursor_on_cell) in r20208.
This now breaks pygtk code like: >>> import gtk >>> model = gtk.ListStore(str) >>> treeview = gtk.TreeView(model) >>> treeview.set_cursor(1) __main__:1: GtkWarning: gtk_tree_view_set_cursor_on_cell: assertion `tree_view->priv->tree != NULL' failed
Kris, is the testcase wrong or is the assertion wrong?
The assertion is wrong and I have fixed this. The function now fails silently again. I have added the test case from comment 5 to the unit tests as well. I have also clarified the new semantics in the documentation. At comment 3: we can look into making the other calls consistent later on -- still need to make up my mind on this. At least set_cursor() can unset the current cursor if the new given path is invalid, scroll_to_cell(), expand and collapse can't do anything when the input is wrong.