Skip to content

Changing the Check State from InitNode may leave the tree in "updating" state #1013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
obones opened this issue Dec 28, 2020 · 1 comment
Closed

Comments

@obones
Copy link
Contributor

obones commented Dec 28, 2020

Following work on issue #820, a change to the CheckState of a given node triggers is a BeginUpdate/EndUpdate call pair to avoid slow propagation to subnodes.
One can set the CheckState from the OnInitNode event handler to have a default state for a given node.
Also, one can access TotalCount which inits all the nodes to get its value. It does so within a try..finally block that directly changes the value of FUpdateCount
This means that if one is to change CheckState from OnInitNode and that the latter is called because of an access to TotalCount, then the (newly) added BeginUpdate/EndUpdate pair sees a value of FUpdateCount that is higher than 0. This has not much impact on BeginUpdate but this prevents EndUpdate from removing the tsUpdating flag from FStates
And once this flag is set, the tree view thinks it is still updating and does not update properly anymore.

This is what the following test application shows: VTVCheckStateInInitNode.zip

Looking at the history of code, it appears GetTotalCount has been doing this direct change of FUpdateCount forever so there must have been a reason not to use BeginUpdate/EndUpdate but I can't figure out why. I mean, even tsUpdating has been available forever.

In my real world application, I was able to avoid reading TotalCount, but my initial change proposal was for GetTotalCount to use BeginUpdate/EndUpdate instead of directly modifying FUpdateCount

What's worrying me, though, is that there are other places where FUpdateCount is changed directly, which means the change introduced by #820 is likely to trigger the same issue with those ones too. Here is the list of those I found:

  • GetTotalCount
  • DeleteChildren
  • SortTree

The last one has a clear explanation as to why it avoids EndUpdate and this leads me to believe that maybe GetTotalCount should be left alone and it's the code inside ChangeCheckState that should do like the three others and directly change the value of FUpdateCount instead of calling BeginUpdate/EndUpdate

What do you think?

@joachimmarder
Copy link
Contributor

I mean, even tsUpdating has been available forever.

I wondered more than once: Why is tsUpdating needed at all? Shouldn't it be equal to FUpdateCount > 0, which we could extract into an IsUpdating method? That would fix the scrollbar issue you reported.

Looking at the history of code, it appears GetTotalCount has been doing this direct change of FUpdateCount forever so there must have been a reason not to use BeginUpdate/EndUpdate but I can't figure out why.

I can only guess. Maybe the idea was: EndUpdate() may involve some costly operations that are unnecessary if just the total node count is queried and the node structure hasn't been changed.

joachimmarder added a commit that referenced this issue Dec 29, 2020
* Partial fix for issue #1013: Changing the Check State from InitNode may leave the tree in "updating" state.
joachimmarder added a commit that referenced this issue Jan 3, 2021
…for flag tsUpdating or (fUpdateCount > 0). Issue #1013.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants