After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 311955 - Using GtkTreeModelFilter and GtkTreeModelSort together can lead to invalid iterators and tons of criticals
Using GtkTreeModelFilter and GtkTreeModelSort together can lead to invalid it...
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkTreeView
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtktreeview-bugs
gtktreeview-bugs
Depends on:
Blocks:
 
 
Reported: 2005-07-29 12:16 UTC by Markku Vire
Modified: 2005-10-25 21:03 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Test application (3.21 KB, text/plain)
2005-07-29 12:19 UTC, Markku Vire
  Details
First try to fix gtktreemodelfilter.c (885 bytes, patch)
2005-07-29 21:36 UTC, Markku Vire
none Details | Review
promised patch, will commit soonish (3.43 KB, patch)
2005-09-13 19:44 UTC, Kristian Rietveld
none Details | Review

Description Markku Vire 2005-07-29 12:16:29 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.
Comment 1 Markku Vire 2005-07-29 12:19:57 UTC
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
Comment 2 Markku Vire 2005-07-29 12:25:27 UTC
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...
Comment 3 Markku Vire 2005-07-29 21:36:56 UTC
Created attachment 49957 [details] [review]
First try to fix gtktreemodelfilter.c

Patch is made against gtk+-2.6.8.
Comment 4 Kristian Rietveld 2005-08-11 23:16:55 UTC
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.
Comment 5 Kristian Rietveld 2005-09-13 19:44:16 UTC
Created attachment 52182 [details] [review]
promised patch, will commit soonish
Comment 6 Kristian Rietveld 2005-10-25 21:03:14 UTC
fixed on HEAD.