I'm struggling with this intermittent crash issue on my UITableView which has UICollectionViews.
I have a navigation controller whose root view controller has:
UITableView with 3 sections
Each section has one row
Each row has a UICollectionView
The top row of UITableView (which is a collection view) is made to scroll automatically based on NSTimer.
The crash occurs when I push into the navigation controller and pop out back and forth. It happens when I do pushing and popping 3-4 times
The trace:
Thread 0 Crashed:
0 libobjc.A.dylib 0x38f74626 objc_msgSend + 6
1 UIKit 0x312a6740 -[UIScrollView(UIScrollViewInternal) _notifyDidScroll] + 60
2 UIKit 0x31020798 -[UIScrollView setContentOffset:] + 600
3 UIKit 0x312a76b6 -[UIScrollView(UIScrollViewInternal) _adjustContentOffsetIfNecessary] + 1394
4 UIKit 0x310d33d2 -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:tramplingDragFlags:] + 414
5 UIKit 0x310d322a -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:] + 26
6 UIKit 0x310d31e2 -[UIScrollView removeFromSuperview] + 26
7 UIKit 0x31001952 -[UIView dealloc] + 374
8 CoreFoundation 0x2e700140 CFRelease + 556
9 CoreFoundation 0x2e70b668 -[__NSArrayM dealloc] + 156
10 libobjc.A.dylib 0x38f79b66 objc_object::sidetable_release(bool) + 170
11 libobjc.A.dylib 0x38f7a0ce (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 354
12 CoreFoundation 0x2e70347c _CFAutoreleasePoolPop + 12
13 CoreFoundation 0x2e798f0e __CFRunLoopRun + 1310
14 CoreFoundation 0x2e703724 CFRunLoopRunSpecific + 520
15 CoreFoundation 0x2e703506 CFRunLoopRunInMode + 102
16 GraphicsServices 0x336726ce GSEventRunModal + 134
17 UIKit 0x3106486c UIApplicationMain + 1132
18 BoatSenzeDev 0x00110648 main (main.m:16)
19 libdyld.dylib 0x39468ab4 start + 0
I think there's a bug somewhere on iOS 8 regarding the timing of UITableViewController (or plain UIViewController containing a UITableView) dealloc when dealing with transition animations. Somehow the view controller is already deallocated, but the table view is still trying to send messages to its delegate.
As a workaround, you can implement the dealloc method on the UITableViewController like this:
- (void)dealloc
{
self.tableView.delegate = nil;
self.tableView.dataSource = nil;
}
Related
In my iPhone app, for some users the app will always crash, whenever they open a certain window. The same window works fine for me and other people, but always causes a crash for some people. It is unclear at this moment what the difference is between people for whom it fails, and for whom it works fine.
The animation to open the specific view will run fine, but will then cause a crash immediately after the animation is finished.
They have sent me the crashlog, but it is hard to understand what is exactly going wrong. I am hoping you can help me understand. The cause for the failure as given by the crashlog is the following exception:
Last Exception Backtrace:
0 CoreFoundation 0x1836ffd38 __exceptionPreprocess + 124
1 libobjc.A.dylib 0x182c14528 objc_exception_throw + 55
2 CoreFoundation 0x18370d1f8 -[NSObject+ 1372664 (NSObject) doesNotRecognizeSelector:] + 139
3 UIKit 0x18cec7cc4 -[UIResponder doesNotRecognizeSelector:] + 295
4 CoreFoundation 0x1837056e4 ___forwarding___ + 1379
5 CoreFoundation 0x1835eb0dc _CF_forwarding_prep_0 + 91
6 CoreFoundation 0x1835d6be8 CFStringAppend + 519
7 CoreFoundation 0x1836bddf0 __CFStringAppendFormatCore + 9271
8 CoreFoundation 0x1836bf658 _CFStringCreateWithFormatAndArgumentsAux2 + 131
9 AccessibilityUtilities 0x192d6b388 _AXStringForArgs + 279
10 UIKit 0x1a242adf8 -[UIViewControllerAccessibility viewDidAppear:] + 267
11 UIKit 0x18cb2869c -[UIViewController _setViewAppearState:isAnimating:] + 851
12 UIKit 0x18cb28c08 -[UIViewController _endAppearanceTransition:] + 227
13 UIKit 0x18cbcee00 -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 1327
14 UIKit 0x1a2440cd4 -[UINavigationControllerAccessibility navigationTransitionView:didEndTransition:fromView:toView:] + 111
15 UIKit 0x18cc96bbc __49-[UINavigationController _startCustomTransition:]_block_invoke + 251
16 UIKit 0x18cc229d8 -[_UIViewControllerTransitionContext completeTransition:] + 115
17 UIKit 0x18cd67d30 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke.124 + 751
18 UIKit 0x18cb47d7c -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 763
19 UIKit 0x18cb4770c -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 311
20 UIKit 0x18cb47418 -[UIViewAnimationState animationDidStop:finished:] + 295
21 UIKit 0x1a2468970 -[UIViewAnimationStateAccessibility animationDidStop:finished:] + 131
22 QuartzCore 0x1876ebd6c CA::Layer::run_animation_callbacks+ 1232236 (void*) + 283
23 libdispatch.dylib 0x183085048 _dispatch_client_callout + 15
24 libdispatch.dylib 0x183091b74 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1015
25 CoreFoundation 0x1836a7f20 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 11
26 CoreFoundation 0x1836a5afc __CFRunLoopRun + 2011
27 CoreFoundation 0x1835c62d8 CFRunLoopRunSpecific + 435
28 GraphicsServices 0x185457f84 GSEventRunModal + 99
29 UIKit 0x18cb73880 UIApplicationMain + 207
30 Flyskyhy 0x10490bd80 main + 32128 (main.m:17)
31 libdyld.dylib 0x1830ea56c start + 3
The crashlog seems to indicate that it goes wrong while doing a CFStringAppend, but it is not clear which string is the problem, or what is wrong with it, or even why a CFStringAppend is needed. All strings visible in the view have been filled in already before the animation starts, and they all are correct.
EDIT:
As requested, here is the code that starts the view. Everything is under a NavigationController, so the new view controller is pushed on the navigation stack to open it.
WaypointEditController *controller = [[WaypointEditController alloc] initWithNibName:#"WayPointEdit" bundle:nil];
controller.navigationItem.title = #"New Waypoint";
// initialisation of other, custom, fields of controller
[self.navigationController pushViewController:controller animated:YES];
The WaypointEditController class that is pushed is derived from UIViewController. The viewWillAppear is overridden, to do initialisation of the fields of the view. But - relevant here - viewDidAppear is not overridden.
In case relevant, here are the most important actions in the viewWillAppear method:
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
self.navigationItem.title = #"New Waypoint";
// other initialisation of internal fields
}
Like you, I have customers reporting this problem and I could see the stack traces that XCode downloaded from production but I could not reproduce it... until I tried enabling "voice over".
The other accessibility options that I tried worked OK.
The stack trace shows that iOS is sending a selector of "length" to an instance of UILabel. This seemed odd. To see what would happen, I added a "length" method to UILabel to return the length of the UILabel's text property. Then it just failed with an unknown selector of _encodingCantBeStoredInEightBitCFString. So clearly iOS thought that my UILabel was something that it wasn't.
This ended up being because "description" was used for the name of my UILabel property/IBOutlet.
To fix the problem I renamed the property from "description" to something different. I suspect that my synthesized "description" getter was overriding NSObject's description method (which returns an NSString which fits the selectors which were being sent to my UILabel).
About 10+ crash reported by crittercism.
Name: SIGSEGV
Reason: SEGV_MAPERR
Seems it is a UIScrollView/UITableView animating or scrolling issue.
How can I find the root cause?
Stack:
0
libobjc.A.dylib 0x0000000195fafbd0 objc_msgSend + 12
1
UIKit 0x00000001892b1db8 -[UIScrollView(UIScrollViewInternal) _delegateScrollViewAnimationEnded] + 64
2
UIKit 0x00000001892b1d30 -[UIScrollView(UIScrollViewInternal) _scrollViewAnimationEnded:finished:] + 204
3
UIKit 0x0000000189366814 -[UIAnimator stopAnimation:] + 500
4
UIKit 0x0000000189366248 -[UIAnimator(Static) _advanceAnimationsOfType:withTimestamp:] + 332
5
QuartzCore 0x0000000188b4629c CA::Display::DisplayLinkItem::dispatch() + 28
6
QuartzCore 0x0000000188b46134 CA::Display::DisplayLink::dispatch_items() + 320
7
IOKit 0x0000000185921470 IODispatchCalloutFromCFMessage + 372
8
CoreFoundation 0x0000000184712dc4 __CFMachPortPerform + 176
9
CoreFoundation 0x0000000184727a54 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
10
CoreFoundation 0x00000001847279b4 __CFRunLoopDoSource1 + 432
11
CoreFoundation 0x0000000184725934 __CFRunLoopRun + 1636
12
CoreFoundation 0x00000001846512d4 CFRunLoopRunSpecific + 392
13
GraphicsServices 0x000000018de676fc GSEventRunModal + 164
14
UIKit 0x0000000189216fac UIApplicationMain + 1484
15
MyApp 0x000000010001d280 main (main.m:14)
16
libdyld.dylib 0x000000019661aa08 start + 0
I've seen this happen when a controller and/or its table is deallocated during an animation. The OS still triggers delegate methods (e.g., -scrollViewDidEndScrollingAnimation: or -scrollViewDidEndDecelerating:) when it finishes with the animation, but because the objects no longer exist things get weird.
The best fix is to nil the delegate in the controller's dealloc method.
Can't reproduce following crash.
I already handled the case : not segueing the viewcontroller while one viewcontroller is animating. Similar problem mentioned here: iOS app error - Can't add self as subview. I have implemented this solution for safe segueing.
Still I am getting following crash.
Note: getting crash on both iOS 7 and 8 but more crash occurrence for iOS 8.(if that helps). Not getting crash in simulator even if segueing from viewDidLoad.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't add self as subview'
Application Specific Backtrace 1:
0 CoreFoundation 0x24503f87 <redacted> + 126
1 libobjc.A.dylib 0x31c62c77 _objc_exception_throw + 38
2 CoreFoundation 0x24503ecd -[NSException initWithCoder:] + 0
3 UIKit 0x279880b3 -[UIView _addSubview:positioned:relativeTo:] + 114
4 UIKit 0x27988037 -[UIView addSubview:] + 30
5 UIKit 0x27b4d491 <redacted> + 1236
6 UIKit 0x2798e701 +[UIView performWithoutAnimation:] + 72
7 UIKit 0x27b4cd79 -[_UINavigationParallaxTransition animateTransition:] + 808
8 UIKit 0x27b0b787 -[UINavigationController _startCustomTransition:] + 2854
9 UIKit 0x27a2ab2f -[UINavigationController _startDeferredTransitionIfNeeded:] + 422
10 UIKit 0x27a2a931 -[UINavigationController __viewWillLayoutSubviews] + 44
11 UIKit 0x27a2a8c9 -[UILayoutContainerView layoutSubviews] + 184
12 UIKit 0x2797f25f -[UIView layoutSublayersOfLayer:] + 514
13 QuartzCore 0x273aa1d5 -[CALayer layoutSublayers] + 136
14 QuartzCore 0x273a5bd1 <redacted> + 360
15 QuartzCore 0x273a5a59 <redacted> + 16
16 QuartzCore 0x273a5447 <redacted> + 222
17 QuartzCore 0x273a5251 <redacted> + 324
18 UIKit 0x27980c31 <redacted> + 1384
19 CoreFoundation 0x244ca807 <redacted> + 14
20 CoreFoundation 0x244c9c1b <redacted> + 222
21 CoreFoundation 0x244c8299 <redacted> + 768
22 CoreFoundation 0x24415db1 _CFRunLoopRunSpecific + 476
23 CoreFoundation 0x24415bc3 _CFRunLoopRunInMode + 106
24 GraphicsServices 0x2b7a0051 _GSEventRunModal + 136
25 UIKit 0x279e0f01 _UIApplicationMain + 1440
This also happens when for some reason you push the segue / viewcontroller multiple times. One of such case is when you are observing for a notification and if for some reason that notification was posted multiple times and in the observing method, if you were pushing a view controller, it will push to more than once which eventually will cause this kind of crash.
Sorry for being late for the party. I recently had this issue wherein my navigationbar goes into corrupted state because of pushing more than one view controller at the same time. This happens because the other view controller is pushed while the first view controller is still animating. Taking hint from the nonamelive answer from here
I came up with my simple solution that works in my case. You just need to subclass UINavigationController and override the pushViewController method and check if previous view controller animation is finished as yet. You can listen to the animation completion by making your class a delegate of UINavigationControllerDelegate and setting the delegate to self.
I have uploaded a gist here to make things simple.
Just make sure you set this new class as the NavigationController in your storyboard.
App crashing when pop two times the navigationController and in iPhone log return this error :(
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x6545f661
Triggered by Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x3a081636 objc_msgSend + 22
1 UIKit 0x322bef20 -[UIScrollView(UIScrollViewInternal) _notifyDidScroll] + 60
2 UIKit 0x32039188 -[UIScrollView setContentOffset:] + 592
3 UIKit 0x320e61e6 -[UITableView setContentOffset:] + 346
4 UIKit 0x322bfe62 -[UIScrollView(UIScrollViewInternal) _adjustContentOffsetIfNecessary] + 1350
5 UIKit 0x320ebd0e -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:tramplingDragFlags:] + 410
6 UIKit 0x320ebb66 -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:] + 26
7 UIKit 0x320ebb22 -[UIScrollView removeFromSuperview] + 26
8 UIKit 0x3201a3b6 -[UIView dealloc] + 374
9 libobjc.A.dylib 0x3a0870d2 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 354
10 CoreFoundation 0x2f730c14 _CFAutoreleasePoolPop + 12
11 CoreFoundation 0x2f7c6176 __CFRunLoopRun + 1302
12 CoreFoundation 0x2f730eba CFRunLoopRunSpecific + 518
13 CoreFoundation 0x2f730c9e CFRunLoopRunInMode + 102
14 GraphicsServices 0x3468a65e GSEventRunModal + 134
15 UIKit 0x3207d148 UIApplicationMain + 1132
16 Big24H 0x000e9728 main (main.m:16)
17 libdyld.dylib 0x3a584ab4 start + 0
Looks like you have a UIScrollViewDelegate being deallocated before its corresponding UIScrollView and then getting called.
You didn't provide any code so the best I can say is you need to find where it is and nil it out when it is getting deallocated.
Probably something like this:
- (void) dealloc
{
myScrollView.delegate = nil;
}
I'm having trouble to diagnostic a crash with UIScrollView
UIKit
-[UIScrollView setContentOffset:]
Exception Type: EXC_BAD_ACCESS Code KERN_INVALID_ADDRESS at 0xe0000008
com.apple.main-thread Crashed
0 libobjc.A.dylib objc_msgSend + 15
1 UIKit -[UIScrollView setContentOffset:] + 618
2 UIKit -[UITableView setContentOffset:] + 330
3 UIKit -[UIScrollView(Static) _adjustContentOffsetIfNecessary] + 1474
4 UIKit -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:tramplingDragFlags:] + 414
5 UIKit -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:] + 30
6 UIKit -[UIScrollView removeFromSuperview] + 30
7 ... UIKit -[UIView dealloc] + 296
8 UIKit -[UIView dealloc] + 296
9 libobjc.A.dylib (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 168
10 CoreFoundation _CFAutoreleasePoolPop + 16
11 CoreFoundation __CFRunLoopRun + 1296
12 CoreFoundation CFRunLoopRunSpecific + 356
13 CoreFoundation CFRunLoopRunInMode + 104
14 GraphicsServices GSEventRunModal + 74
15 UIKit UIApplicationMain + 1120
16 iTV Shows main.m line 12
I had the same problem. Setting the TableView and ScrollView delegates (or any other delegates that you might have) to nil in the dealloc method solved the problem.
- (void)dealloc {
self.tableView.delegate = nil;
self.tableView.dataSource = nil;
}
Its hard to give a concrete answer without seeing your code, but the iOS Debugging Magic technical note is always a great resource with tips for debugging crashes.
Technical Note TN2239: iOS Debugging Magic