skywinder / ActionSheetPicker-3.0

Quickly reproduce the dropdown UIPickerView / ActionSheet functionality on iOS.
http://skywinder.github.io/ActionSheetPicker-3.0
BSD 3-Clause "New" or "Revised" License
3.4k stars 740 forks source link

Crash if the parent becomes a zombie #388

Closed alper closed 6 years ago

alper commented 6 years ago

I have a setup where the viewcontroller that is presenting the ActionSheet can be dismissed before the sheet is displayed. This causes the sheet to show somewhere else and its parent to be a zombie.

I know that is not an ideal setup, but so far I'm fine with it.

The only problem is that pressing cancel on the ActionSheet causes things to hang in my Xcode around this code:

- (IBAction)actionPickerCancel:(id)sender {
    [self notifyTarget:self.target didCancelWithAction:self.cancelAction origin:[self storedOrigin]];
    [self dismissPicker];
}

I'm not even sure how we are getting there. I guess this check still returns true even if the parent is a zombie:

if (target && cancelAction && [target respondsToSelector:cancelAction])

Is there any way to check for this?

The behaviour I would expect: the action sheet disappears and the cancel action on the parent is not executed.

skywinder commented 6 years ago

Hi. can you send a crash message, that appears, I will try to find an error or reporoduce it.

alper commented 6 years ago

I think it's specific for my app but if you can figure it out, here's the done action:

reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010c63b1e6 __exceptionPreprocess + 294
    1   libobjc.A.dylib                     0x000000010bcd0031 objc_exception_throw + 48
    2   CoreFoundation                      0x000000010c67b0bc _CFThrowFormattedException + 194
    3   CoreFoundation                      0x000000010c54e951 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 321
    4   CoreFoundation                      0x000000010c54e7db +[NSDictionary dictionaryWithObjects:forKeys:count:] + 59
    5   Volders                             0x0000000102faa850 -[SelectSubjectViewController continueWithSubject:] + 464
    6   Volders                             0x0000000102faa64d -[SelectSubjectViewController userSelectRow:] + 173
    7   ActionSheetPicker_3_0               0x0000000103e02672 -[ActionSheetStringPicker notifyTarget:didSucceedWithAction:origin:] + 386
    8   ActionSheetPicker_3_0               0x0000000103df81c3 -[AbstractActionSheetPicker actionPickerDone:] + 114
    9   UIKit                               0x0000000106d8d448 -[UIApplication sendAction:to:from:forEvent:] + 83
    10  UIKit                               0x00000001077920d9 __45-[_UIButtonBarTargetAction _invoke:forEvent:]_block_invoke + 154
    11  UIKit                               0x0000000107792012 -[_UIButtonBarTargetAction _invoke:forEvent:] + 154
    12  UIKit                               0x0000000106d8d448 -[UIApplication sendAction:to:from:forEvent:] + 83
    13  UIKit                               0x0000000106f08804 -[UIControl sendAction:to:forEvent:] + 67
    14  UIKit                               0x0000000106f08b21 -[UIControl _sendActionsForEvents:withEvent:] + 450
    15  UIKit                               0x0000000106f07a69 -[UIControl touchesEnded:withEvent:] + 580
    16  UIKit                               0x0000000106e0211f -[UIWindow _sendTouchesForEvent:] + 2729
    17  UIKit                               0x0000000106e03821 -[UIWindow sendEvent:] + 4086
    18  UIKit                               0x0000000106da7370 -[UIApplication sendEvent:] + 352
    19  UIKit                               0x00000001076e857f __dispatchPreprocessedEventFromEventQueue + 2796
    20  UIKit                               0x00000001076eb194 __handleEventQueueInternal + 5949
    21  CoreFoundation                      0x000000010c5ddbb1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    22  CoreFoundation                      0x000000010c5c24af __CFRunLoopDoSources0 + 271
    23  CoreFoundation                      0x000000010c5c1a6f __CFRunLoopRun + 1263
    24  CoreFoundation                      0x000000010c5c130b CFRunLoopRunSpecific + 635
    25  GraphicsServices                    0x0000000110107a73 GSEventRunModal + 62
    26  UIKit                               0x0000000106d8c0b7 UIApplicationMain + 159
    27  Volders                             0x0000000102f99f24 main + 324
    28  libdyld.dylib                       0x000000010df50955 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
alper commented 6 years ago

I think it's specific for my app but if you can figure it out:

reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010c63b1e6 __exceptionPreprocess + 294
    1   libobjc.A.dylib                     0x000000010bcd0031 objc_exception_throw + 48
    2   CoreFoundation                      0x000000010c67b0bc _CFThrowFormattedException + 194
    3   CoreFoundation                      0x000000010c54e951 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 321
    4   CoreFoundation                      0x000000010c54e7db +[NSDictionary dictionaryWithObjects:forKeys:count:] + 59
    5   Volders                             0x0000000102faa850 -[SelectSubjectViewController continueWithSubject:] + 464
    6   Volders                             0x0000000102faa64d -[SelectSubjectViewController userSelectRow:] + 173
    7   ActionSheetPicker_3_0               0x0000000103e02672 -[ActionSheetStringPicker notifyTarget:didSucceedWithAction:origin:] + 386
    8   ActionSheetPicker_3_0               0x0000000103df81c3 -[AbstractActionSheetPicker actionPickerDone:] + 114
    9   UIKit                               0x0000000106d8d448 -[UIApplication sendAction:to:from:forEvent:] + 83
    10  UIKit                               0x00000001077920d9 __45-[_UIButtonBarTargetAction _invoke:forEvent:]_block_invoke + 154
    11  UIKit                               0x0000000107792012 -[_UIButtonBarTargetAction _invoke:forEvent:] + 154
    12  UIKit                               0x0000000106d8d448 -[UIApplication sendAction:to:from:forEvent:] + 83
    13  UIKit                               0x0000000106f08804 -[UIControl sendAction:to:forEvent:] + 67
    14  UIKit                               0x0000000106f08b21 -[UIControl _sendActionsForEvents:withEvent:] + 450
    15  UIKit                               0x0000000106f07a69 -[UIControl touchesEnded:withEvent:] + 580
    16  UIKit                               0x0000000106e0211f -[UIWindow _sendTouchesForEvent:] + 2729
    17  UIKit                               0x0000000106e03821 -[UIWindow sendEvent:] + 4086
    18  UIKit                               0x0000000106da7370 -[UIApplication sendEvent:] + 352
    19  UIKit                               0x00000001076e857f __dispatchPreprocessedEventFromEventQueue + 2796
    20  UIKit                               0x00000001076eb194 __handleEventQueueInternal + 5949
    21  CoreFoundation                      0x000000010c5ddbb1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    22  CoreFoundation                      0x000000010c5c24af __CFRunLoopDoSources0 + 271
    23  CoreFoundation                      0x000000010c5c1a6f __CFRunLoopRun + 1263
    24  CoreFoundation                      0x000000010c5c130b CFRunLoopRunSpecific + 635
    25  GraphicsServices                    0x0000000110107a73 GSEventRunModal + 62
    26  UIKit                               0x0000000106d8c0b7 UIApplicationMain + 159
    27  Volders                             0x0000000102f99f24 main + 324
    28  libdyld.dylib                       0x000000010df50955 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
alper commented 6 years ago

The cancel action does not print out a call stack but just hangs on EXC_BAD_ACCESS at:

[self notifyTarget:self.target didCancelWithAction:self.cancelAction origin:[self storedOrigin]];

alper commented 6 years ago

I can fix my problem by wrapping the presentation of the ActionSheet in a if (self.navigationController) {} but having to think of that always is a bit lame.

skywinder commented 6 years ago

@alper thanks for update. I'm glad, that you found a workaround. I can't reproduce this bug, so I will close this issue for now. Please, let me know, if you have any idea, what causes the problem 👍