GNOME Bugzilla – Bug 125172
gtk.TreeModelSort returns an unusable object
Last modified: 2005-08-22 12:44:36 UTC
Using gtk.TreeModelSort(model) seems to return a model that cannot be used. Attempting to set a TreeView's model with the object issues the following errors: ** (treemodel.py:1363): CRITICAL **: file pygtktreemodel.c: line 535 (pygtk_generic_tree_model_iter_n_children): assertion `iter != NULL' failed (treemodel.py:1363): Gtk-CRITICAL **: file gtktreemodelsort.c: line 2172 (gtk_tree_model_sort_build_level): assertion `length > 0' failed As a testcase, I took the treemodel.py demo file from the pygtk distribution, and modified it from: model = MyTreeModel() tree_view = gtk.TreeView(model) To: model = MyTreeModel() sort_model = gtk.TreeModelSort(mode) tree_view = gtk.TreeView(sort_model) I have tried this with several other models, all with similar results.
Created attachment 20856 [details] Modified treemodel.py file that exhibits the problem
Created attachment 20946 [details] [review] Patch to possibly fix the TreeModelSort problem
This patch looks good. NULL is indeed a valid value for iter, looking at the gtk+ comment (gtk+/gtk/gtktreemodel.c): * gtk_tree_model_iter_n_children: * @tree_model: A #GtkTreeModel. * @iter: The #GtkTreeIter, or %NULL. * * Returns the number of children that @iter has. As a special case, if @iter * is %NULL, then the number of toplevel nodes is returned. * * Return value: The number of children of @iter. NULL as synonym of the model root is used all over the place in GtkTreeModel. Moreover, NULL mapping to python None is usual practice.
*** This bug has been marked as a duplicate of 126479 ***
Created attachment 22841 [details] [review] Updated patch to fix TreeModelSort problem
This was marked as a duplicate of 126479. While the patch for 126479 resolves many of the problems associated with the report, it does not resolve all of them. The testcase originally supplied still does not work. When a new model is returned by TreeModelSort, the TreeModelSort will call pygtk_generic_tree_model_iter_n_children with the iter argument set to NULL, which causes all kinds of problems. The new patch attached should resolve this problem.
Okay, sorry missed that one. Should be fixed in CVS now. Thanks