Skip to content

Fix IndexOutOfRangeException/Infinite loop in UpdateComponent (Track control) #9934

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

Merged
merged 2 commits into from
Mar 5, 2025

Conversation

h3xds1nz
Copy link
Member

@h3xds1nz h3xds1nz commented Oct 11, 2024

Fixes #9904

Description

Fixes IndexOutOfRangeException and infinite loop issues when updating any of Track's children after they've been already set from template or manually.

This issue is present when you attempt to update via any of the public properties (DecreaseRepeatButton, IncreaseRepeatButton, Thumb) after all the public members of Track has already been previously set (and therefore _visualChildren is initialized and has stored all three properties).

In standard Aero2 theme, using a ScrollBar (as Track has no template on its own), the order of the children is:

  • _visualChildren[0] = RepeatButton1
  • _visualChildren[1] = RepeatButton2
  • _visualChildren[2] = Thumb

Setting item at position 2 (which would be Thumb property now) will result in an infinite loop.
Setting items at positions 0 and 1 will result in IndexOutOfRangeException during assigment.

The simplest reproduction code with pure Track goes like this:

Track crashMe = new Track();
crashMe.DecreaseRepeatButton = new RepeatButton();
crashMe.IncreaseRepeatButton = new RepeatButton();
crashMe.Thumb = new Thumb();

// Uncomment this for IndexOutOfRangeException
// crashMe.IncreaseRepeatButton = new RepeatButton();

// Uncomment this for infinite loop
// crashMe.Thumb = new Thumb()

The original code was written with updates in mind but I think it got a bit lost in shifting array members. I have fixed it to behave exactly as described in Track.GetVisualChild and Track.VisualChildrenCount describes (+ the original comments), that means whenever you update an item, the array is shifted to the left if needed, so the order is always from oldest to newest (left to right).
This is aligned with VisualChildrenCount behavior where NULL allows you to remove children basically as well.

Customer Impact

Customers will be finally able to change the Track components as they please and won't experience undocumented behavior and exceptions that were not originally inteded.

Regression

This seems to be present way back. PresentationFramework v3 from NetFX has a bit different code but also buggy.

Testing

Testing the forementioned exceptions and the order of the items, visual refresh, everything seems in order.

Risk

Low, a loop has been fixed to work properly without changing anything else (e.g. collection types, etc.)

Microsoft Reviewers: Open in CodeFlow

himgoyalmicro
himgoyalmicro previously approved these changes Mar 5, 2025
Copy link
Contributor

@himgoyalmicro himgoyalmicro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@himgoyalmicro
Copy link
Contributor

@h3xds1nz this PR is good to be merged. Can you please resolve the merge conflicts?

@h3xds1nz
Copy link
Member Author

h3xds1nz commented Mar 5, 2025

@himgoyalmicro Done :)

Copy link

codecov bot commented Mar 5, 2025

Codecov Report

Attention: Patch coverage is 0% with 17 lines in your changes missing coverage. Please review.

Project coverage is 11.42314%. Comparing base (d94671d) to head (309e50c).
Report is 16 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main       #9934         +/-   ##
===================================================
+ Coverage   10.99508%   11.42314%   +0.42806%     
===================================================
  Files           3215        3214          -1     
  Lines         648472      648613        +141     
  Branches       71534       71527          -7     
===================================================
+ Hits           71300       74092       +2792     
+ Misses        576170      573359       -2811     
- Partials        1002        1162        +160     
Flag Coverage Δ
Debug 11.42314% <0.00000%> (+0.42806%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@himgoyalmicro himgoyalmicro merged commit a778fc0 into dotnet:main Mar 5, 2025
8 checks passed
@himgoyalmicro
Copy link
Contributor

Thank you, @h3xds1nz, for your consistent and valuable contributions. Your hard work is greatly appreciated! 😄

@h3xds1nz
Copy link
Member Author

h3xds1nz commented Mar 5, 2025

@himgoyalmicro Thank you for continuously approving :)

@github-actions github-actions bot locked and limited conversation to collaborators Apr 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Community Contribution A label for all community Contributions PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

infinite loop when assigning the Thumb of a Track
3 participants