Skip to content

fix: prevent MeasureOverride from returning Infinity to Avalonia layout (#2136)#2137

Open
gadfly3173 wants to merge 1 commit intosourcegit-scm:developfrom
gadfly3173:fix/list-measure
Open

fix: prevent MeasureOverride from returning Infinity to Avalonia layout (#2136)#2137
gadfly3173 wants to merge 1 commit intosourcegit-scm:developfrom
gadfly3173:fix/list-measure

Conversation

@gadfly3173
Copy link
Contributor

@gadfly3173 gadfly3173 commented Feb 17, 2026

When VirtualizingStackPanel.ScrollIntoView() measures items, it passes Size.Infinity as the available size. Several custom controls were passing availableSize.Width (or the entire availableSize) straight back in their MeasureOverride return 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 AutoScrollToSelectedItemIfNecessary triggered ScrollIntoView on the virtualized item.

P.S.:
Also applied defensive fixes to CommitRefsPresenter and ImageContainer, which are not related to the reported crash but have the same contract violation — MeasureOverride may return Infinity under certain conditions, you can remove them if you want :

  • CommitRefsPresenter: when AllowWrap is 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: return availableSize as-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.

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

Successfully merging this pull request may close these issues.

1 participant

Comments