fix: prevent MeasureOverride from returning Infinity to Avalonia layout (#2136)#2137
Open
gadfly3173 wants to merge 1 commit intosourcegit-scm:developfrom
Open
fix: prevent MeasureOverride from returning Infinity to Avalonia layout (#2136)#2137gadfly3173 wants to merge 1 commit intosourcegit-scm:developfrom
gadfly3173 wants to merge 1 commit intosourcegit-scm:developfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When
VirtualizingStackPanel.ScrollIntoView()measures items, it passesSize.Infinityas the available size. Several custom controls were passingavailableSize.Width(or the entireavailableSize) straight back in theirMeasureOverridereturn value, which violates Avalonia's layout contract and throws InvalidOperationException.This was most visible on the stash page: selecting stash the 13th+ (beyond the viewport, default window size would be 6+), switching away, then switching back would crash the app because
AutoScrollToSelectedItemIfNecessarytriggeredScrollIntoViewon the virtualized item.P.S.:
Also applied defensive fixes to
CommitRefsPresenterandImageContainer, which are not related to the reported crash but have the same contract violation —MeasureOverridemay return Infinity under certain conditions, you can remove them if you want :CommitRefsPresenter: whenAllowWrapis true, the wrapped branch returns availableSize.Width directly. In practice this branch is unreachable with Infinity input (wrapping never triggers when width is unbounded), but the code still references availableSize.Width in a return path, which is a latent contract violation.ImageContainer: returnavailableSizeas-is when image properties are null. These controls are currently only used in diff views (not in virtualized lists), so the issue is unlikely to surface, but returning raw availableSize from MeasureOverride is always wrong per Avalonia's layout contract.