Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ private void BeginShowToolTip(DependencyObject o, ToolTipService.TriggerAction t
switch (triggerAction)
{
case ToolTipService.TriggerAction.Mouse:
if (SafeArea != null)
if (HasValidSafeArea)
{
// the mouse has moved over a tooltip owner o, while still
// within the safe area of the current tooltip (which must be from mouse).
Expand Down Expand Up @@ -909,8 +909,8 @@ private void SetSafeArea(ToolTip tooltip)

private bool MouseHasLeftSafeArea()
{
// if there is no SafeArea, the mouse didn't leave it
if (SafeArea == null)
// if there is no valid SafeArea, the mouse didn't leave it
if (!HasValidSafeArea)
return false;

// if the current tooltip's owner is no longer being displayed, the safe area is no longer valid
Expand All @@ -926,6 +926,17 @@ private bool MouseHasLeftSafeArea()

private ConvexHull SafeArea { get; set; }

private bool HasValidSafeArea
{
get
{
// There are plenty of Watsons which indicate that source might get disposed
// (i.e. underlying HWND gets destroyed) while we are still holding on it.
// If such a case treat it as if there is no valid safe area.
return SafeArea != null && SafeArea.IsValid;
}
}

#endregion

#endregion
Expand Down Expand Up @@ -1374,6 +1385,8 @@ internal ConvexHull(PresentationSource source, List<NativeMethods.RECT> rects)
}
}

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.

// sort by y (and by x among equal y's)
private void SortPoints(PointList points)
{
Expand Down