Enumeration Mutation During UIView transitionWithView - iphone

I'm experience an occasional crash of my iPhone application where I'm getting the following exception
NSGenericException', reason: '*** Collection <CALayerArray: 0x26f6b0> was mutated while being enumerated.
With the stack trace on the crashing thread of
Thread 0 Crashed:
0 libSystem.B.dylib 0x00078ac8 __kill + 8
1 libSystem.B.dylib 0x00078ab8 kill + 4
2 libSystem.B.dylib 0x00078aaa raise + 10
3 libSystem.B.dylib 0x0008d03a abort + 50
4 libstdc++.6.dylib 0x00044a20 __gnu_cxx::__verbose_terminate_handler() + 376
5 libobjc.A.dylib 0x00005958 _objc_terminate + 104
6 libstdc++.6.dylib 0x00042df2 __cxxabiv1::__terminate(void (*)()) + 46
7 libstdc++.6.dylib 0x00042e46 std::terminate() + 10
8 libstdc++.6.dylib 0x00042f16 __cxa_throw + 78
9 libobjc.A.dylib 0x00004838 objc_exception_throw + 64
10 CoreFoundation 0x0009f850 __NSFastEnumerationMutationHandler + 208
11 libobjc.A.dylib 0x0000a51a objc_enumerationMutation + 18
12 UIKit 0x00007bfe -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] + 142
13 UIKit 0x00007c2e -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:withObject:copySublayers:] + 190
14 UIKit 0x00007cd2 -[UIView(Hierarchy) _makeSubtreePerformSelector:withObject:] + 22
15 UIKit 0x00007628 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 304
16 UIKit 0x000074e8 -[UIView(Hierarchy) addSubview:] + 16
17 UIKit 0x0006c350 +[UIViewControllerWrapperView wrapperViewForView:frame:] + 232
18 UIKit 0x00077d0c -[UINavigationController _startTransition:fromViewController:toViewController:] + 468
19 UIKit 0x00077abc -[UINavigationController _startDeferredTransitionIfNeeded] + 176
20 UIKit 0x00077a00 -[UINavigationController viewWillLayoutSubviews] + 8
21 UIKit 0x0006dca8 -[UILayoutContainerView layoutSubviews] + 132
22 UIKit 0x0000fbc0 -[UIView(CALayerDelegate) _layoutSublayersOfLayer:] + 20
23 CoreFoundation 0x0003e2e4 -[NSObject(NSObject) performSelector:withObject:] + 16
24 QuartzCore 0x0000f942 -[CALayer layoutSublayers] + 114
25 QuartzCore 0x0000f6fa CALayerLayoutIfNeeded + 178
26 QuartzCore 0x000094c4 CA::Context::commit_transaction(CA::Transaction*) + 204
27 QuartzCore 0x000092da CA::Transaction::commit() + 186
28 QuartzCore 0x0002d9b6 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 46
29 CoreFoundation 0x00030236 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 10
30 CoreFoundation 0x000300aa __CFRunLoopDoObservers + 406
31 CoreFoundation 0x000276b4 __CFRunLoopRun + 848
32 CoreFoundation 0x00027270 CFRunLoopRunSpecific + 224
33 CoreFoundation 0x00027178 CFRunLoopRunInMode + 52
34 GraphicsServices 0x000045ec GSEventRunModal + 108
35 GraphicsServices 0x00004698 GSEventRun + 56
36 UIKit 0x0000411c -[UIApplication _run] + 396
37 UIKit 0x00002128 UIApplicationMain + 664
38 iDriveGreen 0x00003026 main (main.m:13)
39 iDriveGreen 0x00002ff0 start + 32
This crash is being triggered after the following code is executed.
StopRouteViewController *stopVC = [[StopRouteViewController alloc] init];
[UIView transitionWithView:self.navigationController.view
duration:0.5
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[self.navigationController pushViewController:stopVC animated:NO];
}
completion:NULL];
[stopVC release];
Does this look blatantly wrong to anyone? My current thought is that is is either tied to stopVC being released before it is pushed or with transitioning with navigationController.view while at the same time pushing a new viewController to the navigationController.
Since this only occurs occasionally, I'd like to have a little more confidence before I commit a potential fix.

Yes, this is incorrect usage of the API. -[UINavigationController pushViewController:animated:] handles animation on its own. Even if you pass NO as the second argument, it is still manipulating the view hierarchy, which is what's causing your crash.
Basically, there is no reason to put a call to -[UINavigationController pushViewController:animated:] in an animation block, as you have done. If you want to animate the push of your controller, pass YES as the second argument.

Related

Need help in finding crash cause

Below are the crash logs from an iPad. I'm getting this crash randomly while I'm pushing and popping out a UIViewController from Navigation controller. Any help/pointer is appreciated.
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000000
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x31430386 _ZL12realizeClassP7class_t + 34
1 libobjc.A.dylib 0x314303e6 _ZL12realizeClassP7class_t + 130
2 libobjc.A.dylib 0x3142a836 prepareForMethodLookup + 74
3 libobjc.A.dylib 0x3142a740 lookUpMethod + 40
4 libobjc.A.dylib 0x3142a70c _class_lookupMethodAndLoadCache3 + 12
5 libobjc.A.dylib 0x31429fc4 objc_msgSend_uncached + 20
6 UIKit 0x3186553e -[UINavigationItem _accumulateViewsFromItems:isLeft:refreshViews:] + 270
7 UIKit 0x31851244 -[UINavigationItem _updateViewsForBarSizeChangeAndApply:] + 124
8 UIKit 0x319e023a __33-[UINavigationBar layoutSubviews]_block_invoke_0 + 250
9 UIKit 0x31838b46 +[UIView(Animation) _performWithoutAnimation:] + 62
10 UIKit 0x3184d2e2 -[UINavigationBar layoutSubviews] + 382
11 UIKit 0x31814f30 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 176
12 CoreFoundation 0x315431f4 -[NSObject performSelector:withObject:] + 36
13 QuartzCore 0x35459a9e -[CALayer layoutSublayers] + 210
14 QuartzCore 0x354596b6 CA::Layer::layout_if_needed(CA::Transaction*) + 210
15 QuartzCore 0x3545d83c CA::Context::commit_transaction(CA::Transaction*) + 220
16 QuartzCore 0x3545d578 CA::Transaction::commit() + 308
17 QuartzCore 0x354554b2 CA:::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 50
18 CoreFoundation 0x315b8b14 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 12
19 CoreFoundation 0x315b6d50 __CFRunLoopDoObservers + 252
20 CoreFoundation 0x315b70aa __CFRunLoopRun + 754
21 CoreFoundation 0x3153a49e CFRunLoopRunSpecific + 294
22 CoreFoundation 0x3153a366 CFRunLoopRunInMode + 98
23 GraphicsServices 0x32a13432 GSEventRunModal + 130
24 UIKit 0x3183fcce UIApplicationMain + 1074
25 SmartClassTPS 0x000b551a main (main.m:16)
26 SmartClassTPS 0x000b5170 start + 32
Was able to figure out long back but forgot to update here. KVO observer not removed! Silly me :-|. BTW thanks for the support. SO rocks.
Most probably you forgot to clear some delegates before releasing an object.

Rare not reproducible crash related to UIKit

I have a random-looking crash related to UIKit and I can't seem to figure out what is wrong.
Does anyone see a familiar pattern here or do you think this might be a random OS-related crash? Is there a way to find out which Buttons or UI-elements were involved here?
Thread 0 Crashed:
0 libobjc.A.dylib 0x35260f78 objc_msgSend + 15
1 UIKit 0x312363d7 -[UIView(Hierarchy) superview] + 50
2 UIKit 0x31239abb -[UIView nextResponder] + 82
3 UIKit 0x31354011 forwardTouchMethod + 36
4 UIKit 0x3124f97d -[UIWindow _sendTouchesForEvent:] + 400
5 UIKit 0x3124f319 -[UIWindow sendEvent:] + 380
6 UIKit 0x31235695 -[UIApplication sendEvent:] + 356
7 UIKit 0x313e762f __42-[UIApplication _cancelTouches:withEvent:]_block_invoke_0 + 54
8 UIKit 0x312a5d0d -[UIApplication _cancelTouches:withEvent:includingGestures:notificationBlock:] + 544
9 UIKit 0x312a5ae9 -[UIApplication _cancelTouches:withEvent:] + 84
10 UIKit 0x31234eb1 _UIApplicationHandleEvent + 5688
11 GraphicsServices 0x33c7722b PurpleEventCallback + 882
12 CoreFoundation 0x37535523 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 38
13 CoreFoundation 0x375354c5 __CFRunLoopDoSource1 + 140
14 CoreFoundation 0x37534313 __CFRunLoopRun + 1370
15 CoreFoundation 0x374b74a5 CFRunLoopRunSpecific + 300
16 CoreFoundation 0x374b736d CFRunLoopRunInMode + 104
17 GraphicsServices 0x33c76439 GSEventRunModal + 136
18 UIKit 0x31263cd5 UIApplicationMain + 1080

MKMapRectIntersectsRect throws EXC_BAD_ACCESS

Is this a problem that is caused by adding map pins/annotations and releasing them too often?
My thread trace shows: 0 obj_msgSend and 1 MKMapRectIntersectsRect which lets me know that adding a pin to the map is the problem.
I have a table view which leads to a detail view which contains the map. It seems that the error is only thrown when I quickly tap into and out of my detail view(from segues of different cells). I tried changing the way I released my annotation and removed it from the map view but to no avail.
Crash Log:
Thread 0 Crashed:
0 libobjc.A.dylib 0x37ab5f78 objc_msgSend + 16
1 MyProject 0x000aa954 0xa2000 + 35156
2 UIKit 0x33181c84 -[UIViewController view] + 160
3 UIKit 0x3318e1e2 -[UIViewController contentScrollView] + 18
4 UIKit 0x3318e052 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 30
5 UIKit 0x3318df38 -[UINavigationController _layoutViewController:] + 28
6 UIKit 0x3318d704 -[UINavigationController _startTransition:fromViewController:toViewController:] + 312
7 UIKit 0x3318d4fc -[UINavigationController _startDeferredTransitionIfNeeded] + 244
8 UIKit 0x33181af8 -[UINavigationController pushViewController:transition:forceImmediate:] + 800
9 UIKit 0x331817ce -[UINavigationController pushViewController:animated:] + 30
10 UIKit 0x331fa8fc -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 880
11 UIKit 0x33274620 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 152
12 Foundation 0x3522e92c __NSFireDelayedPerform + 408
13 CoreFoundation 0x356e8a2c __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 8
14 CoreFoundation 0x356e8692 __CFRunLoopDoTimer + 358
15 CoreFoundation 0x356e7268 __CFRunLoopRun + 1200
16 CoreFoundation 0x3566a49e CFRunLoopRunSpecific + 294
17 CoreFoundation 0x3566a366 CFRunLoopRunInMode + 98
18 GraphicsServices 0x37306432 GSEventRunModal + 130
19 UIKit 0x33176cce UIApplicationMain + 1074
20 MyProject 0x000a3a46 0xa2000 + 6726
21 MyProject 0x000a39f0 0xa2000 + 6640

using testFlight i got my application crash log but don't know what went wrong

I have one application and in beta testing i got my application crash but i am not able to understand what is wrong with it, can you suggest me where to look, Thanks :)
0 TurfNutritionTool_ver_5.1 0x00189642 testflight_backtrace + 142
1 TurfNutritionTool_ver_5.1 0x0018a1d0 TFSignalHandler + 212
2 libsystem_c.dylib 0x3174872e _sigtramp + 42
3 UIKit 0x362f2aa0 -[UITableView dealloc] + 56
4 CoreFoundation 0x317b5c42 -[NSObject(NSObject) release] + 30
5 libobjc.A.dylib 0x3125d50c objc_setProperty_non_gc + 120
6 libobjc.A.dylib 0x31255046 objc_setProperty + 26
7 TurfNutritionTool_ver_5.1 0x001051c8 -[TNTScenarioViewController setScenarioTable:] (TNTScenarioViewController.m:15)
8 TurfNutritionTool_ver_5.1 0x00103610 -[TNTScenarioViewController viewDidUnload] (TNTScenarioViewController.m:160)
9 UIKit 0x362a9a28 -[UIViewController unloadViewForced:] + 172
10 UIKit 0x362b96b8 -[UIViewController unloadViewIfReloadable] + 16
11 UIKit 0x3630012c -[UIViewController purgeMemoryForReason:] + 40
12 UIKit 0x3630014c -[UIViewController didReceiveMemoryWarning] + 16
13 TurfNutritionTool_ver_5.1 0x00102682 -[TNTScenarioViewController didReceiveMemoryWarning] (TNTScenarioViewController.m:40)
14 UIKit 0x36300162 -[UIViewController _didReceiveMemoryWarning:] + 14
15 Foundation 0x3113f182 _nsnote_callback + 142
16 CoreFoundation 0x3182020e __CFXNotificationPost_old + 402
17 CoreFoundation 0x317baeea _CFXNotificationPostNotification + 118
18 Foundation 0x3113c5d2 -[NSNotificationCenter postNotificationName:object:userInfo:] + 70
19 Foundation 0x3113e1c0 -[NSNotificationCenter postNotificationName:object:] + 24
20 UIKit 0x362d6360 -[UIApplication _performMemoryWarning] + 48
21 UIKit 0x362d6d82 -[UIApplication _receivedMemoryNotification] + 126
22 UIKit 0x362d4506 _memoryStatusChanged + 42
23 CoreFoundation 0x31820d68 __CFNotificationCenterDarwinCallBack + 24
24 CoreFoundation 0x3181dbde __CFMachPortPerform + 210
25 CoreFoundation 0x31828a96 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
26 CoreFoundation 0x3182a83e __CFRunLoopDoSource1 + 166
27 CoreFoundation 0x3182b60c __CFRunLoopRun + 520
28 CoreFoundation 0x317bbec2 CFRunLoopRunSpecific + 230
29 CoreFoundation 0x317bbdca CFRunLoopRunInMode + 58
30 GraphicsServices 0x336d641e GSEventRunModal + 114
31 GraphicsServices 0x336d64ca GSEventRun + 62
32 UIKit 0x361abd68 -[UIApplication _run] + 404
33 UIKit 0x361a9806 UIApplicationMain + 670
34 TurfNutritionTool_ver_5.1 0x000edb68 main (main.m:14)
35 TurfNutritionTool_ver_5.1 0x000edb27 start + 39
Are you familiar with the concept of a stack trace? What you are looking at are the lines of code execution from the crash (0) back to a recent frame entry. As such, this is referred to as a 'back trace' since it goes backwards from the point that the code stopped executing.
I have no knowledge of your code, but you can see from line 14 of the back trace that you received a low memory warning. This warning caused a chain of unload events, including a deallocation of a UITableView (line 3).
This is immediately followed by the _sigtramp, which probably indicates an EXC_BAD_ACCESS. My guess, without seeing the rest of your code, is that you are accessing something that has been released by the low memory unload situation.

Core Data causing crash on iPhone 3

I'm getting a strange error with core data. Sometimes, but not all the time my app will crash when I try to access a core data object.
It happens regularly on iPhone 3's and only sometimes on iPhone 4's. I looked at my device log and narrowed it down to an issue with core data. The line the logs refer to is below, tripInstructor is a core data object, its a property of the AppManager class. Not sure if this makes a big difference but I do declare the property as being "nonatomic, retain".
Thanks for any advice
[self.supervisorLbl setText:[AppManager sharedAppManager].tripInstructor.name];
Date/Time: 2011-06-12 20:55:24.865 +1000
OS Version: iPhone OS 4.3.3 (8J2)
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x33e8da1c pthread_kill + 8
1 libsystem_c.dylib 0x35e5b3b4 pthread_kill + 52
2 libsystem_c.dylib 0x35e53bf8 abort + 72
3 libstdc++.6.dylib 0x33508a64 __gnu_cxx::__verbose_terminate_handler() + 376
4 libobjc.A.dylib 0x33f1106c _objc_terminate + 104
5 libstdc++.6.dylib 0x33506e36 _cxxabiv1::_terminate(void (*)()) + 46
6 libstdc++.6.dylib 0x33506e8a std::terminate() + 10
7 libstdc++.6.dylib 0x33506efe __cxa_rethrow + 62
8 libobjc.A.dylib 0x33f10fd8 objc_exception_rethrow + 4
9 CoreData 0x35624f66 _PFFaultHandlerLookupRow + 1450
10 CoreData 0x356799ba -[NSFaultHandler fulfillFault:withContext:] + 14
11 CoreData 0x35678782 _PF_FulfillDeferredFault + 354
12 CoreData 0x35623f18 _sharedIMPL_pvfk_core + 52
13 CoreData 0x35626b68 _pvfk_5 + 4
14 eLogger 0x0000e346 -[VicLogVC viewWillAppear:] (VicLogVC.m:207)
15 UIKit 0x3636bf14 -[UINavigationController _startTransition:fromViewController:toViewController:] + 604
16 UIKit 0x3636bc3c -[UINavigationController _startDeferredTransitionIfNeeded] + 176
17 UIKit 0x3635dd56 -[UINavigationController pushViewController:transition:forceImmediate:] + 634
18 UIKit 0x3635dacc -[UINavigationController pushViewController:animated:] + 28
19 eLogger 0x00025332 -[TripScreenVC _populateAndDisplayVicLog] (TripScreenVC.m:221)
20 eLogger 0x00025492 -[TripScreenVC _determineLogScreen] (TripScreenVC.m:258)
21 eLogger 0x000255d4 -[TripScreenVC buttonPressed:] (TripScreenVC.m:307)
22 CoreFoundation 0x30d4356a -[NSObject(NSObject) performSelector:withObject:withObject:] + 18
23 UIKit 0x36343ec2 -[UIApplication sendAction:to:from:forEvent:] + 78
24 UIKit 0x36343e62 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 26
25 UIKit 0x36343e34 -[UIControl sendAction:to:forEvent:] + 32
26 UIKit 0x36343b86 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 350
27 UIKit 0x3634441c -[UIControl touchesEnded:withEvent:] + 336
28 UIKit 0x36342bee -[UIWindow _sendTouchesForEvent:] + 362
29 UIKit 0x36342568 -[UIWindow sendEvent:] + 256
30 UIKit 0x3632b30c -[UIApplication sendEvent:] + 292
31 UIKit 0x3632ac4c _UIApplicationHandleEvent + 5084
32 GraphicsServices 0x34e2be70 PurpleEventCallback + 660
33 CoreFoundation 0x30daaa90 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 20
34 CoreFoundation 0x30dac838 __CFRunLoopDoSource1 + 160
35 CoreFoundation 0x30dad606 __CFRunLoopRun + 514
36 CoreFoundation 0x30d3debc CFRunLoopRunSpecific + 224
37 CoreFoundation 0x30d3ddc4 CFRunLoopRunInMode + 52
38 GraphicsServices 0x34e2b418 GSEventRunModal + 108
39 GraphicsServices 0x34e2b4c4 GSEventRun + 56
40 UIKit 0x36355d62 -[UIApplication _run] + 398
41 UIKit 0x36353800 UIApplicationMain + 664
42 eLogger 0x00002ff8 main (main.m:14)
43 eLogger 0x00002fa0 start + 32
You are likely holding on to an invalid reference to a managed object, it looks like it was turned into a fault by the managed object context, perhaps after calling -save: or -reset on the context.
If you deleted an object from your store, and still held a reference to the managed object in the ivar then that could be the cause of this error. The object will be deleted by CoreData and turned into a fault when -save: is called (at which point you should nil and reset your ivars). But, when you try to fault the object (by accessing one or more of it's properties) it won't be found in the store because you deleted it.