Xamarin.Forms
Xamarin.Forms copied to clipboard
[Bug] UWP PinchGestureRecognizer - VisualElementTracker:HandlePinch() throws NPE
If an PinchGestureRecognizer is added to an ContentPage or something else the HandlePinch() func throws an null pointer exception!
To Reproduce this NPE you can use the Xamarin.Forms.ControlGallery.WindowsUniversal project in the Xamarin.Forms solution. There you open the 'Pinch gesture effect'.
Basic Information
- Version with issue: latest Xamarin.Forms source version of master (also 5.0.0.2012)
- Last known good version: unknown
- Affected Devices: Microsoft UWP Simulator
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at Xamarin.Forms.Platform.UWP.VisualElementTracker2.HandlePinch(ManipulationDeltaRoutedEventArgs e, View view) at Xamarin.Forms.Platform.UWP.VisualElementTracker
2.OnManipulationDelta(Object sender, ManipulationDeltaRoutedEventArgs e)
Affected Method:
`void HandlePinch(ManipulationDeltaRoutedEventArgs e, View view) { if (_fingers.Count < 2 || view == null) return;
_isPinching = true;
//The following line throws the NPE where e.Container is null Windows.Foundation.Point translationPoint = e.Container.TransformToVisual(Container).TransformPoint(e.Position);
var scaleOriginPoint = new Point(translationPoint.X / view.Width, translationPoint.Y / view.Height);
IEnumerable<PinchGestureRecognizer> pinchGestures = view.GestureRecognizers.GetGesturesFor<PinchGestureRecognizer>();
foreach (PinchGestureRecognizer recognizer in pinchGestures)
{
if (!_wasPinchGestureStartedSent)
{
recognizer.SendPinchStarted(view, scaleOriginPoint);
}
recognizer.SendPinch(view, e.Delta.Scale, scaleOriginPoint);
}
_wasPinchGestureStartedSent = true;
}`
Workaround:
Windows.Foundation.Point translationPoint = Container.TransformToVisual(Container).TransformPoint(e.Position);
Use the Container element from the class property which is equal to e.Container but never be null while pinching.
On appcenter I can see my app crashes because of a nullreferenceexception in VisualElementTracker`2.HandlePinch on a surface go 3 os version 10.0.22000
I find this strange because my app does not use pinch anywhere, it only uses the gesturerecognizers of type tap and swipe.
stack trace:
Xamarin.Forms.Platform.UWP VisualElementTracker
2.HandlePinch (ManipulationDeltaRoutedEventArgs, View)
Xamarin.Forms.Platform.UWP
VisualElementTracker2.OnManipulationDelta (Object, ManipulationDeltaRoutedEventArgs) System.Xml.XmlTextReaderImpl OnDefaultAttributeUseDelegate.Invoke (IDtdDefaultAttributeInfo, XmlTextReaderImpl) __Interop Intrinsics.HasThisCall__31[TArg0] (Object, IntPtr, Object, TArg0) BB.App.UWP!<BaseAddress>+0x3d2e4a0 System.Runtime.InteropServices McgMarshal.ThrowOnExternalCallFailed (Int32, RuntimeTypeHandle) __Interop ComCallHelpers.Call (__ComObject, RuntimeTypeHandle, Int32) __Interop ForwardComStubs.Stub_15[TThis] (__ComObject, Int32) Microsoft.AppCenter.Utils ApplicationLifecycleHelper.<ctor>b__17_1 (Object, UnhandledErrorDetectedEventArgs)
unfortunately i don't have a device with touchscreen so I can't test how it is caused it myself.