SideMenu: Crash when presenting UISideMenuNavigationController under specific circumstances
I have detected a problem (well, not me, my users did) when presenting a UISideMenuNavigationController in a specific scenario.
This happens if I do the following steps:
- Present the UISideMenuNavigationController (with a gesture or pressing a button… it’s indifferent)
- From this UISideMenuNavigationController, I present a view controller (e.g.: UIAlertViewController or MFMailComposeViewController)
- While this view controller is showing, I press the home button
- I go back to the app
- At this moment, the UISideMenuNavigationController is hidden and looks like the view controller I presented is… dismissed?
- Now, if I try to present the UISideMenuNavigationController again… crash!
And this is the crash log:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <App.SideMenuViewController: 0x1f12dba0>.'
*** First throw call stack:
(
0 CoreFoundation 0x09504212 __exceptionPreprocess + 194
1 libobjc.A.dylib 0x08ba8e66 objc_exception_throw + 52
2 UIKit 0x05456975 -[UIViewController _presentViewController:withAnimationController:completion:] + 5740
3 UIKit 0x05459b5a __62-[UIViewController presentViewController:animated:completion:]_block_invoke + 363
4 UIKit 0x05459ec3 -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 535
5 UIKit 0x054599a8 -[UIViewController presentViewController:animated:completion:] + 182
6 SideMenu 0x04f5017c _TZFC8SideMenu18SideMenuTransition20handlePresentMenuPanfCSo22UIPanGestureRecognizerT_ + 2284
7 SideMenu 0x04f4f74c _TZFC8SideMenu18SideMenuTransition31handlePresentMenuLeftScreenEdgefCSo32UIScreenEdgePanGestureRecognizerT_ + 76
8 SideMenu 0x04f4f7e7 _TToZFC8SideMenu18SideMenuTransition31handlePresentMenuLeftScreenEdgefCSo32UIScreenEdgePanGestureRecognizerT_ + 55
9 UIKit 0x058304c7 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 64
10 UIKit 0x05838eea _UIGestureRecognizerSendTargetActions + 109
11 UIKit 0x0583657a _UIGestureRecognizerSendActions + 288
12 UIKit 0x05835434 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 1059
13 UIKit 0x0581fe74 _UIGestureEnvironmentUpdate + 1461
14 UIKit 0x0581f877 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 494
15 UIKit 0x0581ea21 -[UIGestureEnvironment _updateGesturesForEvent:window:] + 259
16 UIKit 0x052ee3b3 -[UIWindow sendEvent:] + 4276
17 UIKit 0x05294d88 -[UIApplication sendEvent:] + 395
18 UIKit 0x05b3c25d __dispatchPreprocessedEventFromEventQueue + 3706
19 UIKit 0x05b3433f __handleEventQueue + 5345
20 CoreFoundation 0x094a3cbf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
21 CoreFoundation 0x09487df7 __CFRunLoopDoSources0 + 519
22 CoreFoundation 0x09487284 __CFRunLoopRun + 1124
23 CoreFoundation 0x09486bab CFRunLoopRunSpecific + 395
24 CoreFoundation 0x09486a0b CFRunLoopRunInMode + 123
25 GraphicsServices 0x0bb7fb4c GSEventRunModal + 177
26 GraphicsServices 0x0bb7f9c7 GSEventRun + 80
27 UIKit 0x0527432b UIApplicationMain + 148
28 MyApp 0x0011d3e1 main + 145
29 libdyld.dylib 0x0ac10799 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 38 (15 by maintainers)
I’m finding a crash after starting signed in (with side menu setup), then logging out, then signing in again. The side menu VC lingers in the view hierarchy in a UITransitionView, thus triggering the crash when trying to open after 2nd sign in. Will try a forced cleanup on signout - maybe this: https://stackoverflow.com/questions/26763020/leaking-views-when-changing-rootviewcontroller-inside-transitionwithview
I found two different solutions for the bug when logging out and logging in.
The correct one: Dismiss the side view.
The easy one: Do not use the
default
singleton. Instead create a new instance every time you need to instantiate a new view that uses the side view.Indeed @jonkykong is correct and this is a fault in our code but the solution is not intuitive enough. Perhaps adding a more descriptive warning before crashing could help
I was facing the same issue while implementing log in/Log out flow
i solved it by following technique. First, when user taps logout, dismiss the menuLeftNavigationController.
SideMenuManager.default.menuLeftNavigationController!.dismiss(animated: true, completion: nil)
use a timer to allow for left menu to dismiss. i have set timer of 1 sec
Upon logout call:
self.view.window!.rootViewController?.dismissViewControllerAnimated(false, completion: nil)
This will remove all active viewcontrollers and the crash message when trying to open the sidemenu will be gone… Took me a while to find this shit
When changing the side view:
[Warning] Side view was not dismissed and this could lead to a crash
Or even better we could support side view changes without dismissal.