Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid NullReferenceException in Gestures.PointerReleased #15117

Merged
Merged
Changes from 1 commit
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
10 changes: 6 additions & 4 deletions src/Avalonia.Base/Input/Gestures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public static class Gestures

private static readonly WeakReference<object?> s_lastPress = new WeakReference<object?>(null);
private static Point s_lastPressPoint;
private static PointerType s_lastHeldPointerType;
private static IPointer? s_lastHeldPointer;

public static readonly RoutedEvent<PinchEventArgs> PinchEvent =
Expand Down Expand Up @@ -229,7 +230,7 @@ private static void PointerPressed(RoutedEventArgs ev)
{
if(s_isHolding && ev.Source is Interactive i)
{
i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Cancelled, s_lastPressPoint, s_lastHeldPointer.Type, e));
i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Cancelled, s_lastPressPoint, s_lastHeldPointerType, e));
}
s_holdCancellationToken?.Cancel();
s_holdCancellationToken?.Dispose();
Expand All @@ -244,6 +245,7 @@ private static void PointerPressed(RoutedEventArgs ev)
{
s_isDoubleTapped = false;
s_lastPress.SetTarget(ev.Source);
s_lastHeldPointerType = e.Pointer.Type;
s_lastHeldPointer = e.Pointer;
s_lastPressPoint = e.GetPosition((Visual)ev.Source);
s_holdCancellationToken = new CancellationTokenSource();
Expand All @@ -257,7 +259,7 @@ private static void PointerPressed(RoutedEventArgs ev)
if (!token.IsCancellationRequested && e.Source is InputElement i && GetIsHoldingEnabled(i) && (e.Pointer.Type != PointerType.Mouse || GetIsHoldWithMouseEnabled(i)))
{
s_isHolding = true;
i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Started, s_lastPressPoint, s_lastHeldPointer.Type, e));
i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Started, s_lastPressPoint, s_lastHeldPointerType, e));
}
}, settings.HoldWaitDuration);
}
Expand Down Expand Up @@ -297,7 +299,7 @@ e.InitialPressMouseButton is MouseButton.Left or MouseButton.Right &&
if (s_isHolding)
{
s_isHolding = false;
i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Completed, s_lastPressPoint, s_lastHeldPointer!.Type, e));
i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Completed, s_lastPressPoint, s_lastHeldPointerType, e));
}
else if (e.InitialPressMouseButton == MouseButton.Right)
{
Expand Down Expand Up @@ -341,7 +343,7 @@ private static void PointerMoved(RoutedEventArgs ev)

if (s_isHolding)
{
i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Cancelled, s_lastPressPoint, s_lastHeldPointer!.Type, e));
maxkatz6 marked this conversation as resolved.
Show resolved Hide resolved
i.RaiseEvent(new HoldingRoutedEventArgs(HoldingState.Cancelled, s_lastPressPoint, s_lastHeldPointerType, e));
s_lastHeldPointer = null;
}
}
Expand Down
Loading