Skip to content

Fixes #4883. NullReferenceException in AdornmentView.Contains when Adornment is null#4884

Merged
tig merged 2 commits intogui-cs:v2_developfrom
YourRobotOverlord:fix/adornmentview-contains-null-ref
Apr 6, 2026
Merged

Fixes #4883. NullReferenceException in AdornmentView.Contains when Adornment is null#4884
tig merged 2 commits intogui-cs:v2_developfrom
YourRobotOverlord:fix/adornmentview-contains-null-ref

Conversation

@YourRobotOverlord
Copy link
Copy Markdown
Collaborator

Fixes #4883.

Summary

AdornmentView.Contains throws a NullReferenceException when Adornment is null. This happens when an AdornmentView or MarginView is created via its parameter-less constructor (e.g. by reflection in the Themes UICatalog scenario), placed inside a SuperView, and the mouse is moved over it.

The Contains override correctly guards against Adornment?.Parent being null and falls back to SuperView — but once SuperView is non-null, execution reaches Adornment!.Thickness.Contains(...) where the null-forgiving ! operator suppresses the compiler warning without preventing the runtime crash.

Fix

Added a null guard for Adornment before the thickness check, consistent with the existing pattern in OnClearingViewport, OnDrawingText, and OnDrawingSubViews.

Testing

Added a regression test in Tests/UnitTestsParallelizable/ViewBase/Adornment/AdornmentViewTests.cs.

@YourRobotOverlord YourRobotOverlord requested a review from tig as a code owner April 5, 2026 02:30
… 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>
@YourRobotOverlord YourRobotOverlord force-pushed the fix/adornmentview-contains-null-ref branch from c073176 to a677aa9 Compare April 5, 2026 02:32
@tig tig merged commit fda6040 into gui-cs:v2_develop Apr 6, 2026
11 checks passed
@YourRobotOverlord YourRobotOverlord deleted the fix/adornmentview-contains-null-ref branch April 6, 2026 18:18
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.

NullReferenceException in AdornmentView.Contains when Adornment is null

2 participants