Fixes #4883. NullReferenceException in AdornmentView.Contains when Adornment is null#4884
Merged
tig merged 2 commits intogui-cs:v2_developfrom Apr 6, 2026
Conversation
… is null AdornmentView has a parameter-less constructor (for AllViewsTester reflection support) that leaves Adornment = null. When such a view is placed inside a SuperView (e.g. the Themes UICatalog scenario creates AdornmentView/MarginView via reflection), moving the mouse over it caused a NullReferenceException at Adornment!.Thickness.Contains(...) because the null-forgiving ! operator did not prevent the dereference. Fix: add a guard clause returning false when Adornment is null, matching the existing pattern used in OnClearingViewport, OnDrawingText, and OnDrawingSubViews. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
c073176 to
a677aa9
Compare
tig
approved these changes
Apr 6, 2026
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.
Fixes #4883.
Summary
AdornmentView.Containsthrows aNullReferenceExceptionwhenAdornmentis null. This happens when anAdornmentVieworMarginViewis created via its parameter-less constructor (e.g. by reflection in the Themes UICatalog scenario), placed inside aSuperView, and the mouse is moved over it.The
Containsoverride correctly guards againstAdornment?.Parentbeing null and falls back toSuperView— but onceSuperViewis non-null, execution reachesAdornment!.Thickness.Contains(...)where the null-forgiving!operator suppresses the compiler warning without preventing the runtime crash.Fix
Added a null guard for
Adornmentbefore the thickness check, consistent with the existing pattern inOnClearingViewport,OnDrawingText, andOnDrawingSubViews.Testing
Added a regression test in
Tests/UnitTestsParallelizable/ViewBase/Adornment/AdornmentViewTests.cs.