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

Fix crash upon rotation while buttons are displayed. #183

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Nomad00
Copy link

@Nomad00 Nomad00 commented Mar 1, 2016

While this does not happen in the demo applications, in my utilization of MGSwipeTableCell the following crash occurs when rotating with the buttons displayed (full stack at end of comment):

*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x7fe891571110> was mutated while being enumerated.'

In the original implementation of refreshContentView, setSwipeOffset: is fired by both self.swipeOffset = 0; & self.swipeOffset = currentOffset; which appears to cause some unhappiness.

This PR changes the two sets such that the custom setters are utilized and are executed serially - resolving my issue.

*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x7fe891571110> was mutated while being enumerated.'

    0   CoreFoundation                      0x0000000108ad1c65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010af2dbb7 objc_exception_throw + 45
    2   CoreFoundation                      0x0000000108ad15c4 __NSFastEnumerationMutationHandler + 132
    3   UIKit                               0x00000001098edf5f -[UIViewController _updateLayoutForStatusBarAndInterfaceOrientation] + 1169
    4   UIKit                               0x00000001098ed897 -[UIViewController window:statusBarWillChangeFromHeight:toHeight:windowSizedViewController:] + 1894
    5   UIKit                               0x00000001098eda70 -[UIViewController window:statusBarWillChangeFromHeight:toHeight:] + 107
    6   UIKit                               0x0000000109811c29 -[UIWindow handleStatusBarChangeFromHeight:toHeight:] + 373
    7   UIKit                               0x0000000109814af0 +[UIWindow _noteStatusBarHeightChanged:oldHeight:forAutolayoutRootViewsOnly:] + 235
    8   UIKit                               0x00000001097bde12 __79-[UIApplication _setStatusBarHidden:animationParameters:changeApplicationFlag:]_block_invoke + 141
    9   UIKit                               0x00000001098343e2 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 473
    10  UIKit                               0x0000000109834678 +[UIView(UIViewAnimationWithBlocks) animateWithDuration:animations:completion:] + 59
    11  UIKit                               0x00000001097bdce0 -[UIApplication _setStatusBarHidden:animationParameters:changeApplicationFlag:] + 491
    12  UIKit                               0x00000001097be97a -[UIApplication setStatusBarOrientation:animationParameters:notifySpringBoardAndFence:] + 1455
    13  UIKit                               0x000000010980f235 __78-[UIWindow _rotateWindowToOrientation:updateStatusBar:duration:skipCallbacks:]_block_invoke1072 + 284
    14  UIKit                               0x0000000109c34100 __58-[_UIWindowRotationAnimationController animateTransition:]_block_invoke + 44
    15  UIKit                               0x00000001098343e2 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 473
    16  UIKit                               0x0000000109834637 +[UIView(UIViewAnimationWithBlocks) animateWithDuration:delay:options:animations:completion:] + 57
    17  UIKit                               0x0000000109c34090 -[_UIWindowRotationAnimationController animateTransition:] + 408
    18  UIKit                               0x000000010980ca09 -[UIWindow _rotateToBounds:withAnimator:transitionContext:] + 761
    19  UIKit                               0x000000010980ec77 -[UIWindow _rotateWindowToOrientation:updateStatusBar:duration:skipCallbacks:] + 1741
    20  UIKit                               0x000000010980f5ba -[UIWindow _setRotatableClient:toOrientation:applyTransformToWindow:updateStatusBar:duration:force:isRotating:] + 559
    21  UIKit                               0x000000010980e52e -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 116
    22  UIKit                               0x000000010980e4b4 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 36
    23  UIKit                               0x000000010980e361 -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 122
    24  UIKit                               0x000000010980d3fe __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 98
    25  UIKit                               0x000000010980d34e -[UIWindow _updateToInterfaceOrientation:duration:force:] + 391
    26  UIKit                               0x000000010980d790 -[UIWindow _updateInterfaceOrientationFromDeviceOrientatilibc++abi.dylib: terminating with uncaught exception of type NSException

Mike Stanziano and others added 2 commits February 29, 2016 15:27
Update `MGSwipeTableCell` `refreshContentView` chain offset adjustments.
This resolves a crash upon rotation within my usage of `MGSwipeTableCell`.
@MortimerGoro
Copy link
Owner

Hi Mike,

That's a weird crash. I would like to understand better why the crash happened. I can't reproduce in the demos, can you try this?

-(void) refreshContentView
{
    CGFloat currentOffset = _swipeOffset;
    BOOL prevValue = _triggerStateChanges;
    _triggerStateChanges = NO;
    if (_displayLink) {
        [_displayLink invalidate];
        _displayLink = nil;
    }
    self.swipeOffset = 0;
    self.swipeOffset = currentOffset;
    _triggerStateChanges = prevValue;
}

or this?

-(void) refreshContentView
{
    CGFloat currentOffset = _swipeOffset;
    BOOL prevValue = _triggerStateChanges;
    _triggerStateChanges = NO;
    self.swipeOffset = 0;
    self.swipeOffset = currentOffset;
    _triggerStateChanges = prevValue;
   if (currentOffset !=0) {
        [self createSwipeViewIfNeeded];
    }
}

@Nomad00
Copy link
Author

Nomad00 commented Mar 3, 2016

Greetings @MortimerGoro!

Both of those implementations yield the crash for me :-/

The stack traces are slightly different, though the error remains the same:

*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x7f9dd3d92160> was mutated while being enumerated.'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000105717e65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000107d10deb objc_exception_throw + 48
    2   CoreFoundation                      0x00000001057177c4 __NSFastEnumerationMutationHandler + 132
    3   UIKit                               0x0000000106516645 -[UIViewController _updateLayoutForStatusBarAndInterfaceOrientation] + 1444
    4   UIKit                               0x0000000106515d58 -[UIViewController window:statusBarWillChangeFromHeight:toHeight:windowSizedViewController:] + 2190
    5   UIKit                               0x0000000106515fff -[UIViewController window:statusBarWillChangeFromHeight:toHeight:] + 147
    6   UIKit                               0x00000001063f9f29 -[UIWindow handleStatusBarChangeFromHeight:toHeight:] + 436
    7   UIKit                               0x00000001063fde30 +[UIWindow _noteStatusBarHeightChanged:oldHeight:forAutolayoutRootViewsOnly:] + 364
    8   UIKit                               0x0000000106380b0a __79-[UIApplication _setStatusBarHidden:animationParameters:changeApplicationFlag:]_block_invoke + 148
    9   UIKit                               0x000000010642a370 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 582
    10  UIKit                               0x000000010642a816 +[UIView(UIViewAnimationWithBlocks) animateWithDuration:animations:completion:] + 92
    11  UIKit                               0x0000000106380994 -[UIApplication _setStatusBarHidden:animationParameters:changeApplicationFlag:] + 653
    12  UIKit                               0x0000000106381b60 -[UIApplication setStatusBarOrientation:animationParameters:notifySpringBoardAndFence:updateBlock:] + 2024
    13  UIKit                               0x00000001063f5d1f __78-[UIWindow _rotateWindowToOrientation:updateStatusBar:duration:skipCallbacks:]_block_invoke1183 + 275
    14  UIKit                               0x0000000106995933 __58-[_UIWindowRotationAnimationController animateTransition:]_block_invoke_2 + 161
    15  UIKit                               0x000000010642f34e +[UIView(Internal) _performBlockDelayingTriggeringResponderEvents:] + 188
    16  UIKit                               0x000000010699575e __58-[_UIWindowRotationAnimationController animateTransition:]_block_invoke + 134
    17  UIKit                               0x000000010642a370 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 582
    18  UIKit                               0x000000010642a7a5 +[UIView(UIViewAnimationWithBlocks) animateWithDuration:delay:options:animations:completion:] + 105
    19  UIKit                               0x000000010699564b -[_UIWindowRotatilibc++abi.dylib: terminating with uncaught exception of type NSException

And

*** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x7f884a54a650> was mutated while being enumerated.'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010270ee65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000104d07deb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010270e7c4 __NSFastEnumerationMutationHandler + 132
    3   UIKit                               0x000000010350d645 -[UIViewController _updateLayoutForStatusBarAndInterfaceOrientation] + 1444
    4   UIKit                               0x000000010350cd58 -[UIViewController window:statusBarWillChangeFromHeight:toHeight:windowSizedViewController:] + 2190
    5   UIKit                               0x000000010350cfff -[UIViewController window:statusBarWillChangeFromHeight:toHeight:] + 147
    6   UIKit                               0x00000001033f0f29 -[UIWindow handleStatusBarChangeFromHeight:toHeight:] + 436
    7   UIKit                               0x00000001033f4e30 +[UIWindow _noteStatusBarHeightChanged:oldHeight:forAutolayoutRootViewsOnly:] + 364
    8   UIKit                               0x0000000103377b0a __79-[UIApplication _setStatusBarHidden:animationParameters:changeApplicationFlag:]_block_invoke + 148
    9   UIKit                               0x0000000103421370 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 582
    10  UIKit                               0x0000000103421816 +[UIView(UIViewAnimationWithBlocks) animateWithDuration:animations:completion:] + 92
    11  UIKit                               0x0000000103377994 -[UIApplication _setStatusBarHidden:animationParameters:changeApplicationFlag:] + 653
    12  UIKit                               0x0000000103378b60 -[UIApplication setStatusBarOrientation:animationParameters:notifySpringBoardAndFence:updateBlock:] + 2024
    13  UIKit                               0x00000001033ecd1f __78-[UIWindow _rotateWindowToOrientation:updateStatusBar:duration:skipCallbacks:]_block_invoke1183 + 275
    14  UIKit                               0x000000010398c933 __58-[_UIWindowRotationAnimationController animateTransition:]_block_invoke_2 + 161
    15  UIKit                               0x000000010342634e +[UIView(Internal) _performBlockDelayingTriggeringResponderEvents:] + 188
    16  UIKit                               0x000000010398c75e __58-[_UIWindowRotationAnimationController animateTransition:]_block_invoke + 134
    17  UIKit                               0x0000000103421370 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 582
    18  UIKit                               0x00000001034217a5 +[UIView(UIViewAnimationWithBlocks) animateWithDuration:delay:options:animations:completion:] + 105
    19  UIKit                               0x000000010398c64b -[_UIWindowRotationAnimationController animateTransition:] + 535
    20  UIKit                               0x00000001033e98fa -[UIWindow _rotateToBounds:withAnimator:transitionContext:] + 656
    21  UIKit                               0x00000001033ec750 -[UIWindow _rotateWindowToOrientation:updateStatusBar:duration:skipCallbacks:] + 2047
    22  UIKit                               0x00000001033ed249 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 842
    23  UIKit                               0x00000001033ebd7c -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 184
    24  UIKit                               0x00000001033ea9cd __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 107
    25  UIKit                               0x00000001033ea805 -[UIWindow _updateToInterfaceOrientation:duration:force:] + 486
    26  CoreFoundation                      0x00000001026db69c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
    27  CoreFoundation                      0x00000001026db3db _CFXRegistrationPost + 427
    28  CoreFoundation                      0x00000001026db142 ___CFXNotificationPost_block_invoke + 50
    29  CoreFoundation                      0x0000000102720972 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1986
    30  CoreFoundation                      0x00000001025d6279 _CFXNotificationPost + 633
    31  Foundation                          0x0000000104896109 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
    32  UIKit                               0x00000001036b2d52 -[UIDevice setOrientation:animated:] + 326
    33  UIKit                               0x000000010339470f __42-[UIApplication handleEvent:withNewEvent:]_block_invoke + 87
    34  UIKit                               0x00000001033942c6 -[UIApplication handleEvent:withNewEvent:] + 929
    35  UIKit                               0x0000000103394ab7 -[UIApplication sendEvent:] + 88
    36  UIKit                               0x00000001163ca871 -[UIApplicationAccessibilitylibc++abi.dylib: terminating with uncaught exception of type NSException

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

Successfully merging this pull request may close these issues.

2 participants