Skip to content

PresentationFramework: Safer tooltip handling#11463

Open
etvorun wants to merge 1 commit intodotnet:mainfrom
etvorun:fix/safer-tooltip-handling
Open

PresentationFramework: Safer tooltip handling#11463
etvorun wants to merge 1 commit intodotnet:mainfrom
etvorun:fix/safer-tooltip-handling

Conversation

@etvorun
Copy link

@etvorun etvorun commented Feb 18, 2026

Summary

Port tooltip safety fix to prevent exceptions when tooltip safe-area source is disposed during hover transitions.

What changed

  • Added HasValidSafeArea gate so tooltip mouse-trigger logic only uses safe area when source is still valid.
  • Updated MouseHasLeftSafeArea to treat invalid/disposed safe area as absent.
  • Added ConvexHull.IsValid to 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

- Preserve original behavior and comments where applicable

- Public-safe wording with minimal, surgical port
@etvorun etvorun requested review from a team and Copilot February 18, 2026 22:53
@dotnet-policy-service dotnet-policy-service bot added the PR metadata: Label to tag PRs, to facilitate with triage label Feb 18, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 HasValidSafeArea property that checks both SafeArea existence and source validity (!_source.IsDisposed)
  • Updated tooltip mouse-trigger logic in BeginShowToolTip to use HasValidSafeArea instead of just null check
  • Updated MouseHasLeftSafeArea to treat invalid/disposed safe area as if it doesn't exist
  • Added ConvexHull.IsValid property to expose underlying source validity

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}
}

internal bool IsValid => !_source.IsDisposed;
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Suggested change
internal bool IsValid => !_source.IsDisposed;
internal bool IsValid => _source != null && !_source.IsDisposed;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR metadata: Label to tag PRs, to facilitate with triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[PresentationFramework] Tooltip safe-area handling can throw during hover transitions

2 participants