PresentationFramework: Safer tooltip handling#11463
PresentationFramework: Safer tooltip handling#11463etvorun wants to merge 1 commit intodotnet:mainfrom
Conversation
- Preserve original behavior and comments where applicable - Public-safe wording with minimal, surgical port
There was a problem hiding this comment.
Pull request overview
This pull request adds safety checks to tooltip handling to prevent exceptions when the tooltip's safe-area source (PresentationSource) is disposed during hover transitions. The fix addresses intermittent crashes that can occur when moving the mouse near tooltip boundaries while tooltips are opening/closing.
Changes:
- Added
HasValidSafeAreaproperty that checks both SafeArea existence and source validity (!_source.IsDisposed) - Updated tooltip mouse-trigger logic in
BeginShowToolTipto useHasValidSafeAreainstead of just null check - Updated
MouseHasLeftSafeAreato treat invalid/disposed safe area as if it doesn't exist - Added
ConvexHull.IsValidproperty to expose underlying source validity
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
| } | ||
|
|
||
| internal bool IsValid => !_source.IsDisposed; |
There was a problem hiding this comment.
The IsValid property should handle the case where _source might be null to prevent potential NullReferenceException. While _source is expected to be non-null based on the constructor being called only when presentationSource is not null (line 844-905), defensive programming suggests checking for null. Consider changing to: internal bool IsValid => _source != null && !_source.IsDisposed;
| internal bool IsValid => !_source.IsDisposed; | |
| internal bool IsValid => _source != null && !_source.IsDisposed; |
Summary
Port tooltip safety fix to prevent exceptions when tooltip safe-area source is disposed during hover transitions.
What changed
HasValidSafeAreagate so tooltip mouse-trigger logic only uses safe area when source is still valid.MouseHasLeftSafeAreato treat invalid/disposed safe area as absent.ConvexHull.IsValidto expose underlying source validity (!_source.IsDisposed).Why
Tooltip handling could race with tooltip window/source teardown, leaving a stale safe-area source and causing coordinate conversion paths to throw. Validating source liveness before safe-area use prevents this failure mode.
Fixes #11462
Microsoft Reviewers: Open in CodeFlow