GestureSample icon indicating copy to clipboard operation
GestureSample copied to clipboard

[iOS] App crash with NullReferenceException at MR.Gestures.iOS.iOSGestureHandler.AddGestureRecognizers(UIView view)

Open MitchBomcanhao opened this issue 1 year ago • 2 comments

I've an app with a structure like so:

  • FlyoutPage
  • the FlyoutPage.Detail is a ContentPage
  • tapping a button on said page opens a Mopups popup page.
  • On this page I have a listview where the item template uses a MR.Gestures.ContentView.

Opening this popup page crashes every single time on iOS. using the same Mr.Gestures-based control on other parts of the app has no issue.

An error occurred: 'Object reference not set to an instance of an object.'. Callstack: ' at MR.Gestures.iOS.iOSGestureHandler.AddGestureRecognizers(UIView view) at MR.Gestures.iOS.iOSGestureHandler.OnElementPropertyChanged(IGestureAwareControl element, UIView view) at MR.Gestures.Handlers.HandlerHelper.<>c.<MapPropertyChanged>b__1_0(IElementHandler handler, IGestureAwareControl element) at MR.Gestures.TaskHelpers.<>c__DisplayClass1_1`2[[Microsoft.Maui.IElementHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[MR.Gestures.IGestureAwareControl, MR.Gestures, Version=4.0.1.0, Culture=neutral, PublicKeyToken=null]].<Debounce>b__3() at Foundation.NSAsyncActionDispatcher.Apply() in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSAction.cs:line 150 at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 58 at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 94

I do not have a repro project for this as when I did try to make one, it somehow never failed - but it does fail on our actual solution, 100% of the time. runs fine on Windows, so it seems platform specific.

The only other relevant bit of data I've found is that if I comment out the event subscriptions for the MR.Gestures.ContentView control (either in xaml or in code), the page loads just fine, but introducing even just one event subscription makes it fail.

Perhaps you can see something in your source code that could point at the issue here?

MitchBomcanhao avatar Feb 22 '24 10:02 MitchBomcanhao

If you don't use any gestures, then AddGestureRecognizers doesn't do anything.

This could occur, if the passed view is null, which happens when in the handler neither ContainerView nor PlatformView is set.

Maybe in your popup these properties are set too late? Try setting the gesture handlers later. After it is shown. Then the view should also already be set.

MichaelRumpler avatar Feb 23 '24 14:02 MichaelRumpler

@MichaelRumpler I've sub/unsubscribed to the gesture events through the control's Loaded/Unloaded events, which seems to have fixed the issue on iOS. Still need to to run this a bit more (and cross platform) to see if any other issues have cropped up.

MitchBomcanhao avatar Feb 26 '24 15:02 MitchBomcanhao