Skip to content

Comments

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

Merged
love-linger merged 1 commit intosourcegit-scm:developfrom
gadfly3173:fix/list-measure
Feb 24, 2026
Merged

fix: prevent MeasureOverride from returning Infinity to Avalonia layout (#2136)#2137
love-linger merged 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.

@love-linger love-linger self-assigned this Feb 24, 2026
@love-linger love-linger added bug Something isn't working labels Feb 24, 2026
@love-linger love-linger merged commit 2179a25 into sourcegit-scm:develop Feb 24, 2026
13 checks passed
@gadfly3173 gadfly3173 deleted the fix/list-measure branch February 24, 2026 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants