iOS - CoreAutoLayout [NSISEngine withAutomaticOptimizationDisabled:] crash - ios

I'm currently having production crashes reported by Firebase pointing to some auto-layout work being done on a background thread. While the fix would be obviously wrapping the offending code on a dispatch main block, we can't find anything pointing to that code.
This scenario seems particularly hard to reproduce - we haven't been able to reproduce it in development.
The crash seems to happen during / after launch, and it varies a little from user to user, which could mean some async work triggering it based on the variance. I checked all the threads provided by the stack trace and couldn't find anything meaningful.
This is the stack trace provided by Firebase - absolutely no mention of app code triggering that update. Wondering if anyone may have some insight.
Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.
Thread that crashes
Fatal Exception: NSInternalInconsistencyException
0 CoreFoundation 0x9270c __exceptionPreprocess
1 libobjc.A.dylib 0x14f04 objc_exception_throw
2 CoreAutoLayout 0x5000 -[NSISEngine withAutomaticOptimizationDisabled:]
3 CoreAutoLayout 0x9e00 -[NSISEngine _optimizeWithoutRebuilding]
4 CoreAutoLayout 0xbd2c -[NSISEngine optimize]
5 CoreAutoLayout 0x49b4 -[NSISEngine performPendingChangeNotifications]
6 UIKitCore 0x3331a0 -[UIView(Hierarchy) layoutSubviews]
7 UIKitCore 0x17c738 -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
8 QuartzCore 0x3cedc CA::Layer::layout_if_needed(CA::Transaction*)
9 QuartzCore 0x2fc90 CA::Layer::layout_and_display_if_needed(CA::Transaction*)
10 QuartzCore 0x4367c CA::Context::commit_transaction(CA::Transaction*, double, double*)
11 QuartzCore 0x4c164 CA::Transaction::commit()
12 QuartzCore 0x9fa08 CA::Transaction::release_thread(void*)
13 libsystem_pthread.dylib 0x3da0 _pthread_tsd_cleanup
14 libsystem_pthread.dylib 0x6c18 _pthread_exit
15 libsystem_pthread.dylib 0x225c pthread_main_np
16 libsystem_pthread.dylib 0x1e98 _pthread_wqthread
17 libsystem_pthread.dylib 0x193c start_wqthread
Main thread trace
com.apple.main-thread
0 libsystem_kernel.dylib 0x14e0 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x1b24 mach_msg + 76
2 CoreFoundation 0x7820 __CFRunLoopServiceMachPort + 372
3 CoreFoundation 0xbcac __CFRunLoopRun + 1180
4 CoreFoundation 0x1f6b8 CFRunLoopRunSpecific + 600
5 GraphicsServices 0x1374 GSEventRunModal + 164
6 UIKitCore 0x513e88 -[UIApplication _run] + 1100
7 UIKitCore 0x2955ec UIApplicationMain + 364
8 MyApp 0x671c main + 20 (main.swift:20)
9 ??? 0x102689ce4 (Missing)

Related

Weird libobjc.a.dylib objc_msgsend crash

Search anywhere and could not found an answer. I have this issue causing the app to crash on many users.
How many?
MANY!
I can't reproduce the crash and I can't understand anything from the Crashlytics logs:
After reading some questions and answers around I suspect that something in ManagedObjectContext cause it.
Already visited:
libobjc.A.dylib objc_msgSend crash occurring with core data usage in background thread
Swift Crash libobjc.A.dylib objc_msgSend
iOS crash libobjc.A.dylib objc_msgSend
Xcode 8.1 release APP crash libobjc.A.dylib objc_msgSend
libobjc.A.dylib objc_msgSend crash occurring with core data usage in background thread
What should I do next?
Crash log:
Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x1b0e720f8 objc_msgSend + 24
1 Foundation 0x19dcb3b90 __NSThreadPerformPerform + 188
2 CoreFoundation 0x19c89c76c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
3 CoreFoundation 0x19c89c668 __CFRunLoopDoSource0 + 208
4 CoreFoundation 0x19c89b9cc __CFRunLoopDoSources0 + 376
5 CoreFoundation 0x19c895a8c __CFRunLoopRun + 824
6 CoreFoundation 0x19c89521c CFRunLoopRunSpecific + 600
7 GraphicsServices 0x1b3914784 GSEventRunModal + 164
8 UIKitCore 0x19f2ce200 -[UIApplication _run] + 1072
9 UIKitCore 0x19f2d3a74 UIApplicationMain + 168
10 ZoomQuizProd 0x102a407b0 main + 19 (AppNotificationManager.swift:19)
11 libdyld.dylib 0x19c5556c0 start + 4

How to track auto layout assertions from background thread

I am getting some auto layout assertions due to UI tasks getting called from background thread. To track this I added a symbolic breakpoint for
-[NSISEngine _optimizeWithoutRebuilding]
This breakpoint is getting called but I don't have the stack trace from my code. I checked all the threads when it hit this assertion and no useful information from where it was invoked in my code.
This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.
Stack:(
0 Foundation 0x000000010cd1752a _AssertAutolayoutOnAllowedThreadsOnly + 77
1 Foundation 0x000000010cd17251 -[NSISEngine _optimizeWithoutRebuilding] + 61
2 Foundation 0x000000010cd1717f -[NSISEngine optimize] + 108
3 Foundation 0x000000010cd123a5 -[NSISEngine performPendingChangeNotifications] + 84
4 UIKitCore 0x00000001187e7cc8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2192
5 QuartzCore 0x000000010da41eae -[CALayer layoutSublayers] + 173
6 QuartzCore 0x000000010da46b88 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 396
7 QuartzCore 0x000000010da52ee4 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 72
8 QuartzCore 0x000000010d9c23aa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 328
9 QuartzCore 0x000000010d9f9584 _ZN2CA11Transaction6commitEv + 608
10 QuartzCore 0x000000010d9fa435 _ZN2CA11Transaction14release_threadEPv + 201
11 libsystem_pthread.dylib 0x0000000115cd66ab _pthread_tsd_cleanup + 551
12 libsystem_pthread.dylib 0x0000000115cd9655 _pthread_exit + 70
13 libsystem_pthread.dylib 0x0000000115cd643a _pthread_wqthread_exit + 74
14 libsystem_pthread.dylib 0x0000000115cd5644 _pthread_wqthread + 472
15 libsystem_pthread.dylib 0x0000000115cd53fd start_wqthread + 13
Question : Is there some other method I should put a breakpoint in or any better way to track this ?
Update: I added the breakpoints as mentioned, it hit the breakpoint but the call stack doesn't show what caused the breakpoint. See screenshots.
I have a simple tableview on a screen, initially I don't get these assertions, just staying on that screen for a while triggers these assertions.

Mysterious iOS crash with tiny stack trace

I have one user, and only one user, that regularly gets the following crash:
Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x0000000192e7a984 objc_object::release() + 8
1 libobjc.A.dylib 0x0000000192e79474 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 524
2 CoreFoundation 0x0000000186855b38 _CFAutoreleasePoolPop + 28
3 CoreFoundation 0x0000000186915124 __CFRunLoopRun + 1460
4 CoreFoundation 0x0000000186855dd0 CFRunLoopRunSpecific + 452
5 GraphicsServices 0x000000018c53dc0c GSEventRunModal + 168
6 UIKit 0x0000000189986fc4 UIApplicationMain + 1156
7 MyApp 0x00000001001a92d0 main (main.m:17)
8 libdyld.dylib 0x0000000193453aa0 start + 4
This is the entire crash, and I have no clue what causes it.
The user has a pretty standard phone, but it only started happening when they got a replacement iPhone 5 earlier this year. Given that timeline and the fact they are the only one with the crash, might the phone itself be at fault?
Is there anywhere I could look for more information to default this information?

Need help to understand following crash log

I am experiencing a strange app crash. I narrowed down the problem to one particular visual component. The app crashes when i navigate back and forth to the screen with this component several time. The strange thing is that same component does not cause crashes on another screen. The problem is that the app does not throw any error when running in debug more. The only thing I see is the crash report in device's log.
I am not sure what code from this component should I provide here. Thus, I will describe what it does in general words. Majority of the layout is coded in xib file which I am loading at runtime. This xib file has number of controls, and UIScrollView is one of the main container. At runtime, I am adding few more UIViews to this scroll view. I am also performing some custom drawing on main CALayer of these added UIViews.
It would be create if somebody can help me narrow down the problem. Also, how can I get more precise report if the issue does not throw any exceptions during debugging?
UPDATE1:
I did further investigations and I think the problem can be narrowed to possibly incorrect disposing. Very similar case is described here (the first comment under the answer). https://stackoverflow.com/a/5359686/3507404
UPDATE2:
It happened that the crash is related to CALayerDelegate. I narrowed down the issue to simple example here. CALayerDelegate disposing issue
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x3b9731f0 __pthread_kill + 8
1 libsystem_pthread.dylib 0x3b9dd792 pthread_kill + 54
2 libsystem_c.dylib 0x3b923fd8 abort + 72
3 MyApp 0x00568df4 mono_handle_native_sigsegv (mini-exceptions.c:2335)
4 MyApp 0x00571dd8 mono_sigsegv_signal_handler (mini.c:6744)
5 libsystem_platform.dylib 0x3b9d7f90 _sigtramp + 40
6 UIKit 0x3302635c -[UIView(Hierarchy) subviews] + 352
7 UIKit 0x331432d4 -[UIView(Hierarchy) _willRemoveSubviewWantingAutolayout:] + 44
8 UIKit 0x332c2056 __UIViewWillBeRemovedFromSuperview + 198
9 UIKit 0x33028af0 -[UIView(Hierarchy) removeFromSuperview] + 56
10 UIKit 0x3302b3b6 -[UIView dealloc] + 374
11 MyApp 0x005fb940 invoke_objc_method_implementation (monotouch-glue.m:1341)
12 MyApp 0x005fb998 monotouch_dealloc_trampoline (monotouch-glue.m:1383)
13 MyApp 0x005fb940 invoke_objc_method_implementation (monotouch-glue.m:1341)
14 MyApp 0x005fb780 monotouch_release_trampoline (monotouch-glue.m:1370)
15 MyApp 0x005fb4bc monotouch_release_managed_ref (monotouch-glue.m:1296)
16 MyApp 0x000f0fa0 (wrapper managed-to-native) MonoTouch.Foundation.NSObject:monotouch_release_managed_ref + 88
17 MyApp 0x000c6228 MonoTouch.Foundation.NSObject:ReleaseManagedRef (.pmcs-compat.NSObject.cs:197)
18 MyApp 0x000c658c MonoTouch.Foundation.NSObject/NSObject_Disposer:Drain (.pmcs-compat.NSObject2.cs:1320)
19 MyApp 0x00234d48 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 196
20 MyApp 0x00573eb4 mono_jit_runtime_invoke (mini.c:6610)
21 MyApp 0x005b00f2 mono_runtime_invoke (object.c:2827)
22 MyApp 0x005379f6 native_to_managed_trampoline_MonoTouch_Foundation_NSObject_NSObject_Disposer_Drain (registrar.m:135)
23 Foundation 0x311f7c6e __NSThreadPerformPerform + 382
24 CoreFoundation 0x307d9208 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 12
25 CoreFoundation 0x307d86d6 __CFRunLoopDoSources0 + 202
26 CoreFoundation 0x307d6eca __CFRunLoopRun + 618
27 CoreFoundation 0x30741eba CFRunLoopRunSpecific + 518
28 CoreFoundation 0x30741c9e CFRunLoopRunInMode + 102
29 GraphicsServices 0x3566865e GSEventRunModal + 134
30 UIKit 0x3308e148 UIApplicationMain + 1132
31 MyApp 0x000f6454 (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain + 268
32 MyApp 0x000d2468 MonoTouch.UIKit.UIApplication:Main (.pmcs-compat.UIApplication.cs:75)
33 MyApp 0x00059144 KarmaMobile.iOS.Application:Main (Main.cs:46)
34 MyApp 0x00234d48 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 196
35 MyApp 0x00573eb4 mono_jit_runtime_invoke (mini.c:6610)
36 MyApp 0x005b00f2 mono_runtime_invoke (object.c:2827)
37 MyApp 0x005b3c78 mono_runtime_exec_main (object.c:4052)
38 MyApp 0x005b3ac8 mono_runtime_run_main (object.c:3678)
39 MyApp 0x0056250c mono_jit_exec (driver.g.c:1009)
40 MyApp 0x005e69a0 main (main.m:489)
41 libdyld.dylib 0x3b8bdab4 start + 0

How can I debug this crash log

I get this crash log from my device log after that my app is crashed. Before crash I clicked on cancel button from search bar inside UITableView.
How can I understand what and where is the problem ?
how can I debug this kind of log from production device?
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x3b74b1fc __pthread_kill + 8
1 libsystem_pthread.dylib 0x3b7b2a4e pthread_kill + 54
2 libsystem_c.dylib 0x3b6fc028 abort + 72
3 libc++abi.dylib 0x3ab4a98a abort_message + 70
4 libc++abi.dylib 0x3ab636e2 default_terminate_handler() + 250
5 libobjc.A.dylib 0x3b19b936 _objc_terminate() + 190
6 libc++abi.dylib 0x3ab611b0 std::__terminate(void (*)()) + 76
7 libc++abi.dylib 0x3ab60d12 __cxa_rethrow + 98
8 libobjc.A.dylib 0x3b19b80a objc_exception_rethrow + 38
9 CoreFoundation 0x30d724e2 CFRunLoopRunSpecific + 638
10 CoreFoundation 0x30d7224e CFRunLoopRunInMode + 102
11 GraphicsServices 0x35aac2e6 GSEventRunModal + 134
12 UIKit 0x33627840 UIApplicationMain + 1132
13 MYAPPNAME 0x000ffc44 0xfa000 + 23620
14 libdyld.dylib 0x3b694ab4 start + 0
------- EDITED ------
i get Last Exception Backtrace:
0 CoreFoundation 0x30e3ee7e __exceptionPreprocess + 126
1 libobjc.A.dylib 0x3b19b6c2 objc_exception_throw + 34
2 CoreFoundation 0x30e3ed50 +[NSException raise:format:arguments:] + 100
3 Foundation 0x317e70aa -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 86
4 UIKit 0x33796348 -[UITableView _endCellAnimationsWithContext:] + 7940
5 MYAPPNAME 0x00233972 0xfa000 + 1284466
6 MYAPPNAME 0x00232e3c 0xfa000 + 1281596
7 MYAPPNAME 0x00232fd8 0xfa000 + 1282008
8 MYAPPNAME 0x002319d4 0xfa000 + 1276372
9 Foundation 0x3181933a __NSFireDelayedPerform + 410
10 CoreFoundation 0x30e09e7a
__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 10
11 CoreFoundation 0x30e09a96 __CFRunLoopDoTimer + 790
12 CoreFoundation 0x30e07e1e __CFRunLoopRun + 1214
13 CoreFoundation 0x30d7246c CFRunLoopRunSpecific + 520
14 CoreFoundation 0x30d7224e CFRunLoopRunInMode + 102
15 GraphicsServices 0x35aac2e6 GSEventRunModal + 134
16 UIKit 0x33627840 UIApplicationMain + 1132
17 MYAPPNAME 0x000ffc44 0xfa000 + 23620
18 libdyld.dylib 0x3b694ab2 tlv_initializer + 2
The crash happened because of an unhandled exception.
While symbolicating the crash report with the Xcode organizer usually helps, it doesn't help in this case, since stack frame 13 will only show something like main (main.m:14).
If the crash report doesn't contain an Last Exception Backtrace section, the report is basically meaningless.
Try to reproduce the crash while running the app with the debugger or integrate a 3rd party crash report solution that is able to provide the Last Exception Backtrace and also the Application Information section which gives you the detailed exception error.
There are many 3rd party solutions out there, I won't recommend any, since I would be biased :)
Update: As you now provided the Last Exception Backtrace it shows that there is an Assertion triggered when a tableview animation is ending. Once you symbolicates the crash report you'll see which lines of code in your app are causing this.

Resources