MichaelRumpler / GestureSample

Sample App for MR.Gestures
MIT License
56 stars 17 forks source link

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

Open MitchBomcanhao opened 4 months ago

MitchBomcanhao commented 4 months ago

I've an app with a structure like so:

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.b1_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]].b3() 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?

MichaelRumpler commented 4 months ago

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.

MitchBomcanhao commented 4 months ago

@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.