I am currently working on an iOS app which crashes and generates the crash report provided below.We think that the app is crashing due to mutation while Fast Enumeration but the error is occurring in NSISEngine.
We also think that the issue is related to constraints of a Table View. This Table View shows info fetched from Rest Services and we are programmatically updating the DataSource in viewWillAppear().
Some of the constraints we are adding programmatically which are as follows:
Method:
1.cellForRowAtIndexPath()
Constraints:
a. Updated UILabel with attributed String to set line height:
[attributedString addAttribute:NSFontAttributeName value:self.font range:NSMakeRange(0, text.length)];
self.attributedText = attributedString;
b. Updated UIImage:
myCell.myLogo.layer.masksToBounds =YES;
myCell.myLogo.layer.opaque = NO;
[[myCell.myLogo layer] setCornerRadius:4.];
c. Border for Table View cell
mySecondCell.secondCellContainerView.layer.masksToBounds = YES;
[mySecondCell.secondCellContainerView.layer setCornerRadius:3.7];
[mySecondCell.secondCellContainerView addBorderWithColorRed:@214 Green:@214 Blue:@214];
[myCell.myLogo addBorderWithColorRed:@214 Green:@214 Blue:@214];
Constraints: We are calculating height on the basis of the content which is dynamic.
We are using StoryBoard and some of the constraints are set there using Auto Layout.
I searched a lot however was unable to find a crash report similar to the one my app generated. I am new to iOS programming. Can somebody help me with debugging this crash report? If there is a constraint causing this issue, can somebody help me figure out the same? Thanks in advance.
Incident Identifier: F155875B-9FD3-425F-85B9-7595617AF52A
CrashReporter Key: aaa79870161ff1e371394b881a26e97f0066f464
Hardware Model: iPhone5,2
Process: myapp [611]
Path: /var/mobile/Applications/40D6D77C-1DBB-4F6B-BEE1-73A67C789C49/myapp.app/myapp
Identifier: com.myapp
Version: 1.0 (0.9)
Code Type: ARM (Native)
Parent Process: launchd [1]
Date/Time: 2013-10-17 11:16:45.559 +0530
OS Version: iOS 7.0.2 (11A501)
Report Version: 104
Exception Type: EXC_CRASH (SIGTRAP)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x2fc9fe86 __exceptionPreprocess + 126
1 libobjc.A.dylib 0x39f9a6c2 objc_exception_throw + 34
2 CoreFoundation 0x2fc9f974 __NSFastEnumerationMutationHandler + 124
3 Foundation 0x30604f32 -[NSISEngine substituteOutAllOccurencesOfBodyVar:withExpression:] + 438
4 Foundation 0x30607ba2 -[NSISEngine pivotToMakeBodyVar:newHeadOfRowWithHead:andDropRow:] + 334
5 Foundation 0x3060594c -[NSISEngine minimizeConstantInObjectiveRowWithHead:] + 232
6 Foundation 0x3060546e -[NSISEngine optimize] + 170
7 Foundation 0x306011a8 -[NSISEngine withBehaviors:performModifications:] + 312
8 UIKit 0x32424490 -[UIView(Hierarchy) _postMovedFromSuperview:] + 292
9 UIKit 0x3243114e -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1398
10 UIKit 0x32447a9c -[UIView(Hierarchy) insertSubview:atIndex:] + 32
11 UIKit 0x325fb888 -[UINavigationBar _wrapView:inClippingViewWithLeftBoundary:rightBoundary:leftMaskImage:leftMaskIsChevron:rightMaskImage:] + 240
12 UIKit 0x325b505e -[UINavigationBar _startPopAnimationFromItems:fromBarStyle:toItems:toBarStyle:] + 1982
13 UIKit 0x324f1b88 -[UINavigationBar popNavigationItem] + 1316
14 UIKit 0x324f14a0 -[UINavigationBar _popNavigationItemWithTransition:] + 556
15 UIKit 0x326f02ac ___popViewControllerNormal_block_invoke + 152
16 UIKit 0x324d43a0 -[UINavigationController _startDeferredTransitionIfNeeded:] + 868
17 UIKit 0x324d3fe4 -[UINavigationController __viewWillLayoutSubviews] + 40
18 UIKit 0x324d3f78 -[UILayoutContainerView layoutSubviews] + 180
19 UIKit 0x3242552e -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 342
20 QuartzCore 0x320acf3e -[CALayer layoutSublayers] + 138
21 QuartzCore 0x320a8762 CA::Layer::layout_if_needed(CA::Transaction*) + 346
22 QuartzCore 0x320a85f4 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 12
23 QuartzCore 0x320a8008 CA::Context::commit_transaction(CA::Transaction*) + 224
24 QuartzCore 0x320a7e1a CA::Transaction::commit() + 310
25 QuartzCore 0x320d5436 CA::Transaction::release_thread(void*) + 158
26 libsystem_pthread.dylib 0x3a5af9b0 _pthread_tsd_cleanup + 160
27 libsystem_pthread.dylib 0x3a5af732 _pthread_exit + 82
28 libsystem_pthread.dylib 0x3a5b04b8 pthread_exit + 24
29 Foundation 0x305d7ac6 +[NSThread exit] + 6
30 Foundation 0x30683de0 __NSThread__main__ + 1088
31 libsystem_pthread.dylib 0x3a5b0c58 _pthread_body + 136
32 libsystem_pthread.dylib 0x3a5b0bca _pthread_start + 98
33 libsystem_pthread.dylib 0x3a5aeccc thread_start + 4
Thread 0 Crashed:
0 libsystem_malloc.dylib 0x3a572596 szone_free_definite_size + 1510
1 UIFoundation 0x3754aab4 -[NSAttributeDictionaryEnumerator dealloc] + 68
2 libobjc.A.dylib 0x39fa5b06 objc_object::sidetable_release(bool) + 170
3 libobjc.A.dylib 0x39f9701e (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 354
4 QuartzCore 0x320a1b54 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 64
5 CoreFoundation 0x2fc6af6e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 18
6 CoreFoundation 0x2fc688fa __CFRunLoopDoObservers + 282
7 CoreFoundation 0x2fc68c46 __CFRunLoopRun + 734
8 CoreFoundation 0x2fbd353c CFRunLoopRunSpecific + 520
9 CoreFoundation 0x2fbd331e CFRunLoopRunInMode + 102
10 GraphicsServices 0x3490a2e6 GSEventRunModal + 134
11 UIKit 0x3248a1e0 UIApplicationMain + 1132
12 myapp 0x000aac16 main (main.mm:16)
13 libdyld.dylib 0x3a493ab4 start + 0
Thread 1:
0 libsystem_kernel.dylib 0x3a537838 kevent64 + 24
1 libdispatch.dylib 0x3a4860d0 _dispatch_mgr_invoke + 228
2 libdispatch.dylib 0x3a48063e _dispatch_mgr_thread + 34
Thread 2 name: com.apple.NSURLConnectionLoader
Thread 2:
0 libsystem_kernel.dylib 0x3a537a84 mach_msg_trap + 20
1 libsystem_kernel.dylib 0x3a53787c mach_msg + 36
2 CoreFoundation 0x2fc6a55c __CFRunLoopServiceMachPort + 152
3 CoreFoundation 0x2fc68c7c __CFRunLoopRun + 788
4 CoreFoundation 0x2fbd353c CFRunLoopRunSpecific + 520
5 CoreFoundation 0x2fbd331e CFRunLoopRunInMode + 102
6 Foundation 0x3060e64c +[NSURLConnection(Loader) _resourceLoadLoop:] + 316
7 Foundation 0x30683dc2 __NSThread__main__ + 1058
8 libsystem_pthread.dylib 0x3a5b0c5a _pthread_body + 138
9 libsystem_pthread.dylib 0x3a5b0bca _pthread_start + 98
10 libsystem_pthread.dylib 0x3a5aeccc thread_start + 4
Thread 3 name: com.apple.CFSocket.private
Thread 3:
0 libsystem_kernel.dylib 0x3a54a440 select$DARWIN_EXTSN + 20
1 CoreFoundation 0x2fc6e45e __CFSocketManager + 482
2 libsystem_pthread.dylib 0x3a5b0c5a _pthread_body + 138
3 libsystem_pthread.dylib 0x3a5b0bca _pthread_start + 98
4 libsystem_pthread.dylib 0x3a5aeccc thread_start + 4
[12:37:06 PM] Devika Deshmukh: Thread 4:
0 libsystem_kernel.dylib 0x3a537a84 mach_msg_trap + 20
1 libsystem_kernel.dylib 0x3a53787c mach_msg + 36
2 CoreFoundation 0x2fc6a55c __CFRunLoopServiceMachPort + 152
3 CoreFoundation 0x2fc68c7c __CFRunLoopRun + 788
4 CoreFoundation 0x2fbd353c CFRunLoopRunSpecific + 520
5 CoreFoundation 0x2fbd331e CFRunLoopRunInMode + 102
6 Foundation 0x305c1822 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 250
7 Foundation 0x30612664 -[NSRunLoop(NSRunLoop) run] + 76
8 myapp 0x00197bdc +[AFURLConnectionOperation networkRequestThreadEntryPoint:] (AFURLConnectionOperation.m:160)
9 Foundation 0x30683dc2 __NSThread__main__ + 1058
10 libsystem_pthread.dylib 0x3a5b0c5a _pthread_body + 138
11 libsystem_pthread.dylib 0x3a5b0bca _pthread_start + 98
12 libsystem_pthread.dylib 0x3a5aeccc thread_start + 4
Thread 5:
0 libsystem_c.dylib 0x3a4fb09e __abort + 102
1 libsystem_c.dylib 0x3a4fb034 abort + 84
2 myapp 0x001bd8ea ___lldb_unnamed_function5196$$myapp + 22
3 CoreFoundation 0x2fca018a __handleUncaughtException + 578
4 libobjc.A.dylib 0x39f9a924 _objc_terminate() + 172
5 libc++abi.dylib 0x399601b0 std::__terminate(void (*)()) + 76
6 libc++abi.dylib 0x3995fa04 __cxa_throw + 112
7 libobjc.A.dylib 0x39f9a796 objc_exception_throw + 246
8 CoreFoundation 0x2fc9f974 __NSFastEnumerationMutationHandler + 124
9 Foundation 0x30604f32 -[NSISEngine substituteOutAllOccurencesOfBodyVar:withExpression:] + 438
10 Foundation 0x30607ba2 -[NSISEngine pivotToMakeBodyVar:newHeadOfRowWithHead:andDropRow:] + 334
11 Foundation 0x3060594c -[NSISEngine minimizeConstantInObjectiveRowWithHead:] + 232
12 Foundation 0x3060546e -[NSISEngine optimize] + 170
13 Foundation 0x306011a8 -[NSISEngine withBehaviors:performModifications:] + 312
14 UIKit 0x32424490 -[UIView(Hierarchy) _postMovedFromSuperview:] + 292
15 UIKit 0x3243114e -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1398
16 UIKit 0x32447a9c -[UIView(Hierarchy) insertSubview:atIndex:] + 32
17 UIKit 0x325fb888 -[UINavigationBar _wrapView:inClippingViewWithLeftBoundary:rightBoundary:leftMaskImage:leftMaskIsChevron:rightMaskImage:] + 240
18 UIKit 0x325b505e -[UINavigationBar _startPopAnimationFromItems:fromBarStyle:toItems:toBarStyle:] + 1982
19 UIKit 0x324f1b88 -[UINavigationBar popNavigationItem] + 1316
20 UIKit 0x324f14a0 -[UINavigationBar _popNavigationItemWithTransition:] + 556
21 UIKit 0x326f02ac ___popViewControllerNormal_block_invoke + 152
22 UIKit 0x324d43a2 -[UINavigationController _startDeferredTransitionIfNeeded:] + 870
23 UIKit 0x324d3fe4 -[UINavigationController __viewWillLayoutSubviews] + 40
24 UIKit 0x324d3f78 -[UILayoutContainerView layoutSubviews] + 180
25 UIKit 0x3242552e -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 342
26 QuartzCore 0x320acf3e -[CALayer layoutSublayers] + 138
27 QuartzCore 0x320a8762 CA::Layer::layout_if_needed(CA::Transaction*) + 346
28 QuartzCore 0x320a85f4 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 12
29 QuartzCore 0x320a8008 CA::Context::commit_transaction(CA::Transaction*) + 224
30 QuartzCore 0x320a7e1a CA::Transaction::commit() + 310
31 QuartzCore 0x320d5436 CA::Transaction::release_thread(void*) + 158
32 libsystem_pthread.dylib 0x3a5af9b2 _pthread_tsd_cleanup + 162
33 libsystem_pthread.dylib 0x3a5af732 _pthread_exit + 82
34 libsystem_pthread.dylib 0x3a5b04b8 pthread_exit + 24
35 Foundation 0x305d7ac6 +[NSThread exit] + 6
36 Foundation 0x30683de0 __NSThread__main__ + 1088
37 libsystem_pthread.dylib 0x3a5b0c5a _pthread_body + 138
38 libsystem_pthread.dylib 0x3a5b0bca _pthread_start + 98
39 libsystem_pthread.dylib 0x3a5aeccc thread_start + 4
Thread 6:
0 libsystem_kernel.dylib 0x3a54ac7c __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x3a5aee06 _pthread_wqthread + 306
2 libsystem_pthread.dylib 0x3a5aecc0 start_wqthread + 4
Thread 0 crashed with ARM Thread State (32-bit):
r0: 0x00280a00 r1: 0xfffff000 r2: 0x17f9a000 r3: 0x0000000c
r4: 0x17f99650 r5: 0x3c32fe08 r6: 0x3c32fe00 r7: 0x27d5cb50
r8: 0x00000001 r9: 0x00000fff r10: 0x17f99650 r11: 0x0000008a
ip: 0x17f99db0 sp: 0x27d5cb4c lr: 0x39f96e39 pc: 0x3a572596
cpsr: 0x20000030
Update:
Following is the code by which we are populating our datasource:
(void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
viewWillAppearFlag = true;
if(dataFetched) {
[self setupDatasourceDetails:self.myData];
}
}
(void) setupDatasourceDetails:(NSArray *)data {
self.datasource = [MyDatasource new];
self.datasource.data=data;
[self.myTable setDataSource:self.datasource];
[self.myTable setDelegate:self.datasource];
[self.myTable reloadData];
}
//Callback from REST services
(void) onDataFetched:(NSArray *)data{
dataFetched=true;
self.myData=data;
if(viewWillAppearFlag){
[self setupDatasourceDetails:self.myData]; //the event which will occur later(either viewWillAppear or dataFetched) calls setupDatasourceDetails
}
}
Update:
The error is occurring while transition back from one view controller to another (in navigation controller).
We are using [self.navigationController popViewControllerAnimated:YES]; to transition back to the previous view controller. The transition is happening on the Main thread.
Let us know if any more information is required.
Update
It seems that our problem has been resolved. We moved the functionality from viewWillAppear to viewDidAppear. This fix seems to have resolved the issue. Does anyone know the reason why this fix worked? Please let us know. Thanks.
Two suggestions:
strong
property (not
weak
) (and the data property on MyDatasource
)Make sure
onDataFetched:
is called on the main queue. If unsure, use this
dispatching mechanism instead:
dispatch_async(dispatch_get_main_queue(), ^{
// all update code here
});
I don't think the error is directly in the code you posted, but:
NSFastEnumerationMutationHandler
is raised when you are editing an array or dictionary while enumerating it. For example this is wrong:
for ( id obj in anArray ) {
if ( [obj shouldRemove == YES ) {
[anArray removeObject:obj];
}
}
If you need to do that you should work with a copy of an array or use filteredArrayUsingPredicate.
Can't see all of your code, but I am thinking you need to call layoutIfNeeded before setting the constraints as the views are not calculated before ViewWillAppear. The fact that it succeeds in ViewDidAppear is because the elements have been calculated. Alternately, you could try your code in DidLayoutSubviews.
User contributions licensed under CC BY-SA 3.0