GNOME Bugzilla – Bug 311955
Using GtkTreeModelFilter and GtkTreeModelSort together can lead to invalid iterators and tons of criticals
Last modified: 2005-10-25 21:03:14 UTC
Version details: Seems to quite version independent Distribution/Version: Debian I have the following structure in my program (I'll attach a simplified tester later...): GtkTreeView => GtkTreeModelFilter => GtkTreeModelSort => My own model When inserting/removing nodes in certain fashion I get iterator caches out of sync: * level cache for GtkTreeModelSort is cleared * BUT level cache for GtkTreeModelFilter is still there. => This causes that GtkTreeView will show a node having children even though there is none. When I expand this node, garbage is shown and terminal is flooded by critical warnings. How to reproduce: 1) Model setup as stated above. 2) Insert node with child and have it in collapsed mode 3) Insert new node to same level as collapsed node so that filter model filters it out. 4) Remove the child node from collapsed node (should not show any children any more, but treeview still shows an expander) 5) try to expand the collapsed node. Now garbage appears... What actually happens: In step 3) GtkTreeModelSort clears it's level cache. Now child is no longer in cache. BUT: Because GtkTreeModelFilter filters out the inserted node, it's cache stays. This leads into situation that models have different states.
Created attachment 49926 [details] Test application Run the attached tester. * Wait until all nodes are appended (a couple of visible ones and one hidden). * Press remove button once (now the expander should dissapear, but it does not). * Try to expand the node with child * Check the output from console
When one tries to expand the node (which shouldn't have children any more), gtk_tree_model_filter_convert_iter_to_child_iter is called. Within this function gtk_tree_model_get_iter fails (returning false). However, the parameter iterator is still used normally. This iterator causes the critical messages that appear in console. However, this is just one side effect of the fact that iterator caches are out of sync...
Created attachment 49957 [details] [review] First try to fix gtktreemodelfilter.c Patch is made against gtk+-2.6.8.
Jonathan and I discussed this problem today, and the fix is not really trivial. Patch id=49957 is not going to work reliably, we can think of situations where the filter model will not get a row-has-child-toggled signal when it actually does need one, which will cause model disparaties again. Basically we think that the filter model should have a ref on all child nodes (nodes with a parent node, nodes in the root level do not count) in the child model. I've been hacking on a patch implementing this, the reffing part already works (and fixes the problem demonstrated in the testcase), the unreffing part needs some more thought before I can implement that. Hopefully I will get to that tomorrow.
Created attachment 52182 [details] [review] promised patch, will commit soonish
fixed on HEAD.