Fix IndexOutOfRangeException/Infinite loop in UpdateComponent (Track control) #9934
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #9904
Description
Fixes
IndexOutOfRangeException
and infinite loop issues when updating any ofTrack
'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
(asTrack
has no template on its own), the order of the children is: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: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 whereNULL
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