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

NullReferenceException when dismissing 'DismissAsync()' BottomSheet #130

Open
Aeonitis opened this issue Aug 14, 2024 · 1 comment
Open

Comments

@Aeonitis
Copy link

Aeonitis commented Aug 14, 2024

When attempting to dismiss the BottomSheet component in The49.Maui.BottomSheet library, the application throws a NullReferenceException, causing the app to terminate unexpectedly. This issue occurs consistently when interacting with the touch events that trigger the dismissal of the BottomSheet.

You do seem to have closed a similar issue in the past, #94. This issue appears to occur specifically when dismissing the BottomSheet using touch events. It could be related to a missing or null object reference within the NotifyDismissed() method or related methods in the dismissal process. I also wonder if DismissAsync() not running on main thread or not matters at all in this issue...

Steps to Reproduce

  • Open the app and trigger the display of the BottomSheet.
  • Attempt to dismiss the BottomSheet via touch event.
  • Observe the crash and the exception thrown.

Expected Behavior
The BottomSheet should be dismissed without throwing any exceptions, and the app should continue to function normally.

Actual Behavior
The application throws a NullReferenceException, leading to the app termination. The exception seems to be thrown from the NotifyDismissed() method in the BottomSheet class.

Logs & Stack Trace

 ------ ------------ -------- -------- --- Released Finger at {X=769, Y=1379}.
-> Attempting to dismiss sheet
Exception thrown: 'System.NullReferenceException' in The49.Maui.BottomSheet.dll
2024-08-14 18:50:36.983515+0100 AppName-Maui[48890:17402555] *** Terminating app due to uncaught exception 'System.NullReferenceException', reason: 'Object reference not set to an instance of an object. (System.NullReferenceException)
   at The49.Maui.BottomSheet.BottomSheet.NotifyDismissed()
   at ObjCRuntime.Trampolines.SDAction.Invoke(IntPtr block) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/ObjCRuntime/Trampolines.g.cs:line 17012
   at UIKit.UIViewController.DismissViewController(Boolean animated, Action completionHandler) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/UIKit/UIViewController.g.cs:line 396
   at The49.Maui.BottomSheet.BottomSheetHandler.Dismiss(BottomSheet view, Object request)
   at The49.Maui.BottomSheet.BottomSheetHandler.MapDismiss(BottomSheetHandler handler, BottomSheet view, Object request)
Exception thrown: 'ObjCRuntime.ObjCException' in Microsoft.iOS.dll
   at Microsoft.Maui.CommandMapper`2.<>c__DisplayClass6_0[[The49.Maui.BottomSheet.BottomSheet, The49.Maui.BottomSheet, Version=8.0.3.0, Culture=neutral, PublicKeyToken=null]
*** Terminating app due to uncaught exception 'System.NullReferenceException', reason: 'Object reference not set to an instance of an object. (System.NullReferenceException)
   at The49.Maui.BottomSheet.BottomSheet.NotifyDismissed()
   at ObjCRuntime.Trampolines.SDAction.Invoke(IntPtr block) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/ObjCRuntime/Trampolines.g.cs:line 17012
   at UIKit.UIViewController.DismissViewController(Boolean animated, Action completionHandler) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/UIKit/UIViewController.g.cs:line 396
Exception thrown: 'ObjCRuntime.ObjCException' in Microsoft.iOS.dll
   at The49.Maui.BottomSheet.BottomSheetHandler.Dismiss(BottomSheet view, Object request)
   at The49.Maui.BottomSheet.BottomSheetHandler.MapDismiss(BottomSheetHandler handler, BottomSheet view, Object request)
   at Microsoft.Maui.CommandMapper`2.<>c__DisplayClass6_0[[The49.Maui.BottomSheet.BottomSheet, The49.Maui.BottomSheet, Version=8.0.3.0, Culture=neutral, PublicKeyToken=null],[The49.Maui.BottomSheet.BottomSheetHandler, The49.Maui.BottomSheet, Version=8.0.3.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v, Object o)
   at Microsoft.Maui.CommandMapper.InvokeCore(String key, IElementHandler viewHandler, IElement virtualView, Object args)
   at Microsoft.Maui.CommandMapper.Invoke(IElementHandler viewHandler, IElement virtualView, String property, Object args)
   at Microsoft.Maui.Handlers.ElementHandler.Invoke(String command, Object args)
   at The49.Maui.BottomSheet.BottomSheet.DismissAsync(Boolean animated)
   at Aeonitis.Util.UXHandler.HideCaseSheet() in /Users/aeonitis/dev/_AppName/AppName-Maui/AppName-Maui/util/UXHandler.cs:line 232
   at Aeonitis.Util.TouchHandler.HandleTouch(SKCanvasView canvasView, DeckNode rootNode, DeckNode selectedNode, SKTouchEventArgs e) in /Users/aeonitis/dev/_AppName/AppName-Maui/AppName-Maui/util/TouchHandler.cs:line 131
   at AppName_Maui.DrawPage.OnCanvasViewTouchAsync(Object sender, SKTouchEventArgs e) in /Users/aeonitis/dev/_AppName/AppName-Maui/AppName-Maui/DrawPage.xaml.cs:line 84
   at SkiaSharp.Views.Maui.Controls.SKCanvasView.OnTouch(SKTouchEventArgs e)
   at SkiaSharp.Views.Maui.Controls.SKCanvasView.SkiaSharp.Views.Maui.ISKCanvasView.OnTouch(SKTouchEventArgs e)
   at SkiaSharp.Views.Maui.Handlers.SKCanvasViewHandler.<>c__DisplayClass7_0.<MapEnableTouchEvents>b__0(SKTouchEventArgs args)
Exception thrown: 'ObjCRuntime.ObjCException' in Microsoft.iOS.dll
   at SkiaSharp.Views.Maui.Platform.SKTouchHandler.FireEvent(SKTouchAction actionType, UITouch touch, Boolean inContact)
   at SkiaSharp.Views.Maui.Platform.SKTouchHandler.TouchesEnded(NSSet touches, UIEvent evt)
'
*** First throw call stack:
(
	0   CoreFoundation                      0x00000001804ae138 __exceptionPreprocess + 172
	1   libobjc.A.dylib                     0x0000000180087db4 objc_exception_throw + 56
	2   libxamarin-dotnet-debug.dylib       0x0000000103bfef6c xamarin_process_managed_exception + 1052
	3   libxamarin-dotnet-debug.dylib       0x0000000103bfea94 xamarin_process_managed_exception_gchandle + 68
	4   libxamarin-dotnet-debug.dylib       0x0000000103bfea44 xamarin_ftnptr_exception_handler + 24
	5   libmonosgen-2.0.dylib               0x0000000104e839f0 mono_handle_exception_internal + 5252
Exception thrown: 'ObjCRuntime.ObjCException' in Microsoft.iOS.dll
	6   libmonosgen-2.0.dylib               0x0000000104e82560 mono_handle_exception + 44
	7   libmonosgen-2.0.dylib               0x0000000104ee4350 interp_throw + 160
	8   libmonosgen-2.0.dylib               0x0000000104ee259c interp_throw_ex_general + 156
	9   libmonosgen-2.0.dylib               0x0000000104edd5a0 mono_interp_exec_method + 25236
	10  libmonosgen-2.0.dylib               0x0000000104ed5088 interp_entry_from_trampoline + 548
	11  AppName-Maui                          0x0000000102579a18 native_to_interp_trampoline + 104
	12  UIKitCore                           0x0000000184cc0838 -[UIViewController dismissViewControllerWithTransition:completion:] + 2124
	13  UIKitCore                           0x0000000184cbfe24 -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 452
	14  UIKitCore                           0x0000000184cc1e64 -[UIViewController dismissViewControllerAnimated:completion:] + 120
	15  libxamarin-dotnet-debug.dylib       0x0000000103c14c9c xamarin_dyn_objc_msgSendSuper + 164
	16  AppName-Maui                          0x000000010257995c interp_to_native_trampoline + 156
Exception thrown: 'ObjCRuntime.ObjCException' in Microsoft.iOS.dll
	17  libmonosgen-2.0.dylib               0x0000000104ee376c ves_pinvoke_method + 584
	18  libmonosgen-2.0.dylib               0x0000000104ed7ef8 mono_interp_exec_method + 3052
	19  libmonosgen-2.0.dylib               0x0000000104ed59c0 interp_runtime_invoke + 244
	20  libmonosgen-2.0.dylib               0x0000000104deec64 mono_jit_runtime_invoke + 1116
	21  libmonosgen-2.0.dylib               0x0000000104fa9d10 mono_runtime_invoke_checked + 148
	22  libmonosgen-2.0.dylib               0x0000000104faddd4 mono_runtime_invoke + 544
	23  libxamarin-dotnet-debug.dylib       0x0000000103c0bd84 xamarin_invoke_trampoline + 5376
	24  libxamarin-dotnet-debug.dylib       0x0000000103c13c80 xamarin_arch_trampoline + 148
	25  libxamarin-dotnet-debug.dylib       0x0000000103c14a60 xamarin_arm64_common_trampoline + 64
	26  UIKitCore                           0x0000000184f2dd70 -[UIGestureRecognizer _componentsEnded:withEvent:] + 140
	27  UIKitCore                           0x000000018546c448 -[UITouchesEvent _sendEventToGestureRecognizer:] + 556
	28  UIKitCore                           0x0000000184f21e4c -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 160
	29  UIKitCore                           0x0000000184f21c3c -[UIGestureEnvironment _updateForEvent:window:] + 156
Exception thrown: 'ObjCRuntime.ObjCException' in Microsoft.iOS.dll
	30  UIKitCore                           0x0000000185421df8 -[UIWindow sendEvent:] + 3088
	31  UIKitCore                           0x00000001854017c8 -[UIApplication sendEvent:] + 576
	32  UIKitCore                           0x00000001854849d8 __dispatchPreprocessedEventFromEventQueue + 1684
	33  UIKitCore                           0x0000000185487824 __processEventQueue + 5524
	34  UIKitCore                           0x0000000185480218 __eventFetcherSourceCallback + 156
	35  CoreFoundation                      0x000000018040ee88 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
	36  CoreFoundation                      0x000000018040edd0 __CFRunLoopDoSource0 + 172
	37  CoreFoundation                      0x000000018040e540 __CFRunLoopDoSources0 + 232
	38  CoreFoundation                      0x0000000180408c28 __CFRunLoopRun + 768
	39  CoreFoundation                      0x0000000180408514 CFRunLoopRunSpecific + 572
Exception thrown: 'ObjCRuntime.ObjCException' in Microsoft.iOS.dll
	40  GraphicsServices                    0x000000018ef06ae4 GSEventRunModal + 160
	41  UIKitCore                           0x00000001853e8040 -[UIApplication _run] + 868
	42  UIKitCore                           0x00000001853ebcc8 UIApplicationMain + 124
	43  libxamarin-dotnet-debug.dylib       0x0000000103bcff00 xamarin_UIApplicationMain + 60
	44  libmonosgen-2.0.dylib               0x0000000104ee4b30 do_icall + 316
	45  libmonosgen-2.0.dylib               0x0000000104ee33d0 do_icall_wrapper + 356
	46  libmonosgen-2.0.dylib               0x0000000104ed7e20 mono_interp_exec_method + 2836
	47  libmonosgen-2.0.dylib               0x0000000104ed59c0 interp_runtime_invoke + 244
	48  libmonosgen-2.0.dylib               0x0000000104deec64 mono_jit_runtime_invoke + 1116
	49  libmonosgen-2.0.dylib               0x0000000104fa9d10 mono_runtime_invoke_checked + 148
	50  libmonosgen-2.0.dylib               0x0000000104fb12f0 mono_runtime_exec_main_checked + 116
Exception thrown: 'ObjCRuntime.ObjCException' in Microsoft.iOS.dll
	51  libmonosgen-2.0.dylib               0x0000000104e42eec mono_jit_exec + 364
	52  libxamarin-dotnet-debug.dylib       0x0000000103c13b00 xamarin_main + 2320
	53  AppName-Maui                          0x000000010265ab44 main + 72
	54  dyld                                0x0000000102bd5544 start_sim + 20
	55  ???                                 0x0000000102e6a0e0 0x0 + 4343636192
	56  ???                                 0xe50d800000000000 0x0 + 16504988946871091200
Exception thrown: 'ObjCRuntime.ObjCException' in Microsoft.iOS.dll
)
2024-08-14 18:50:36.985520+0100 AppName-Maui[48890:17402555] *** Terminating app due to uncaught exception 'System.NullReferenceException', reason: 'Object reference not set to an instance of an object. (System.NullReferenceException)
   at The49.Maui.BottomSheet.BottomSheet.NotifyDismissed()
   at ObjCRuntime.Trampolines.SDAction.Invoke(IntPtr block) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/ObjCRuntime/Trampolines.g.cs:line 17012
   at UIKit.UIViewController.DismissViewController(Boolean animated, Action completionHandler) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/UIKit/UIViewController.g.cs:line 396
   at The49.Maui.BottomSheet.BottomSheetHandler.Dismiss(BottomSheet view, Object request)
   at The49.Maui.BottomSheet.BottomSheetHandler.MapDismiss(BottomSheetHandler handler, BottomSheet view, Object request)
   at Microsoft.Maui.CommandMapper`2.<>c__DisplayClass6_0[[The49.Maui.BottomSheet.BottomSheet, The49.Maui.BottomSheet, Version=8.0.3.0, Culture=neutral, PublicKeyToken=null]
Exception thrown: 'ObjCRuntime.ObjCException' in Microsoft.iOS.dll
*** Terminating app due to uncaught exception 'System.NullReferenceException', reason: 'Object reference not set to an instance of an object. (System.NullReferenceException)
   at The49.Maui.BottomSheet.BottomSheet.NotifyDismissed()
   at ObjCRuntime.Trampolines.SDAction.Invoke(IntPtr block) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/ObjCRuntime/Trampolines.g.cs:line 17012
   at UIKit.UIViewController.DismissViewController(Boolean animated, Action completionHandler) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/UIKit/UIViewController.g.cs:line 396
   at The49.Maui.BottomSheet.BottomSheetHandler.Dismiss(BottomSheet view, Object request)
   at The49.Maui.BottomSheet.BottomSheetHandler.MapDismiss(BottomSheetHandler handler, BottomSheet view, Object request)
Exception thrown: 'ObjCRuntime.ObjCException' in Microsoft.iOS.dll
   at Microsoft.Maui.CommandMapper`2.<>c__DisplayClass6_0[[The49.Maui.BottomSheet.BottomSheet, The49.Maui.BottomSheet, Version=8.0.3.0, Culture=neutral, PublicKeyToken=null],[The49.Maui.BottomSheet.BottomSheetHandler, The49.Maui.BottomSheet, Version=8.0.3.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v, Object o)
   at Microsoft.Maui.CommandMapper.InvokeCore(String key, IElementHandler viewHandler, IElement virtualView, Object args)
   at Microsoft.Maui.CommandMapper.Invoke(IElementHandler viewHandler, IElement virtualView, String property, Object args)
   at Microsoft.Maui.Handlers.ElementHandler.Invoke(String command, Object args)
   at The49.Maui.BottomSheet.BottomSheet.DismissAsync(Boolean animated)
   at Aeonitis.Util.UXHandler.HideCaseSheet() in /Users/aeonitis/dev/_AppName/AppName-Maui/AppName-Maui/util/UXHandler.cs:line 232
   at Aeonitis.Util.TouchHandler.HandleTouch(SKCanvasView canvasView, DeckNode rootNode, DeckNode selectedNode, SKTouchEventArgs e) in /Users/aeonitis/dev/_AppName/AppName-Maui/AppName-Maui/util/TouchHandler.cs:line 131
Exception thrown: 'ObjCRuntime.ObjCException' in Microsoft.iOS.dll
   at AppName_Maui.DrawPage.OnCanvasViewTouchAsync(Object sender, SKTouchEventArgs e) in /Users/aeonitis/dev/_AppName/AppName-Maui/AppName-Maui/DrawPage.xaml.cs:line 84
   at SkiaSharp.Views.Maui.Controls.SKCanvasView.OnTouch(SKTouchEventArgs e)
Exception thrown: 'ObjCRuntime.ObjCException' in Microsoft.iOS.dll
   at SkiaSharp.Views.Maui.Controls.SKCanvasView.SkiaSharp.Views.Maui.ISKCanvasView.OnTouch(SKTouchEventArgs e)
   at SkiaSharp.Views.Maui.Handlers.SKCanvasViewHandler.<>c__DisplayClass7_0.<MapEnableTouchEvents>b__0(SKTouchEventArgs args)
   at SkiaSharp.Views.Maui.Platform.SKTouchHandler.FireEvent(SKTouchAction actionType, UITouch touch, Boolean inContact)
   at SkiaSharp.Views.Maui.Platform.SKTouchHandler.TouchesEnded(NSSet touches, UIEvent evt)

Environment
Library Version: 8.0.3.0
Operating System: iOS
Device: iPhone 15 Pro max (Simulator)
Development Platform: .NET 8 Maui (C#)
Build Configuration: Debug

@Aeonitis Aeonitis changed the title NullReferenceException when dismissing BottomSheet NullReferenceException when dismissing 'DismissAsync()' BottomSheet Aug 14, 2024
@williambuchanan2
Copy link

I am having a lot of different issues with these bottom sheets including the same issue as reported here. The strange thing is the app doesn't crash when I call the method to hide the bottom sheet. It's only after I navigate away from the page that the below exception gets thrown, but for some reason the call stack shows the exception being raised by the 'Hide' method:

Error Type: System.NullReferenceException
Error Message: Arg_NullReferenceException
Stack Trace: at The49.Maui.BottomSheet.BottomSheet.NotifyDismissed()
at UIKit.UIViewController.DismissViewController(Boolean , Action )
at The49.Maui.BottomSheet.BottomSheetHandler.Dismiss(BottomSheet view, Object request)
at The49.Maui.BottomSheet.BottomSheetHandler.MapDismiss(BottomSheetHandler handler, BottomSheet view, Object request)
at Microsoft.Maui.CommandMapper`2.<>c__DisplayClass6_0[[The49.Maui.BottomSheet.BottomSheet, The49.Maui.BottomSheet, Version=8.0.3.0, Culture=neutral, PublicKeyToken=null],[The49.Maui.BottomSheet.BottomSheetHandler, The49.Maui.BottomSheet, Version=8.0.3.0, Culture=neutral, PublicKeyToken=null]].b__0(IElementHandler h, IElement v, Object o)
at Microsoft.Maui.CommandMapper.InvokeCore(String key, IElementHandler viewHandler, IElement virtualView, Object args)
at Microsoft.Maui.CommandMapper.Invoke(IElementHandler viewHandler, IElement virtualView, String property, Object args)
at Microsoft.Maui.Handlers.ElementHandler.Invoke(String command, Object args)
at The49.Maui.BottomSheet.BottomSheet.DismissAsync(Boolean animated)
at PDS.App.RedSix.Controls.RedSixMasterPage.HideOrgSelectBottomSheet()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants