How to track auto layout assertions from background thread - ios

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.

Related

iOS - CoreAutoLayout [NSISEngine withAutomaticOptimizationDisabled:] crash

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)

In iPad pro 11.2.5 App get crashed

In my app, I have used one textfield. When tap on textfield the device keyboard will appear and than I type some text in that textfield. On that time the app get crashed in iPad Pro 11.2.5 version. I don't know why the app getting crashed because the same code works perfect in iPad Pro 10.3 version. Please review the my crash analytics report below
Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x184410430 objc_msgSend + 16
1 CoreFoundation 0x18514513c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20
2 CoreFoundation 0x1851446dc _CFXRegistrationPost + 420
3 CoreFoundation 0x185144440 ___CFXNotificationPost_block_invoke + 60
4 CoreFoundation 0x1851c1e24 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1408
5 CoreFoundation 0x18507ad60 _CFXNotificationPost + 380
6 Foundation 0x185aa7348 -[NSNotificationCenter postNotificationName:object:userInfo:] + 68
7 UIFoundation 0x18f8c4570 -[NSTextStorage processEditing] + 240
8 UIFoundation 0x18f8c41d8 -[NSTextStorage endEditing] + 92
9 UIKit 0x18e914368 -[UITextInputController _insertText:fromKeyboard:] + 488
10 UIKit 0x18e9136d0 -[UITextInputController insertText:] + 400
11 UIKit 0x18ead3518 -[UIFieldEditor insertFilteredText:] + 968
12 UIKit 0x18f3eb3a0 -[UITextField insertFilteredText:] + 104
13 UIKit 0x18e91343c -[UIKeyboardImpl insertText:] + 136
14 UIKit 0x18ebd735c -[UIKeyboardImpl performKeyboardOutput:] + 756
15 UIKit 0x18ebd665c __55-[UIKeyboardImpl handleKeyboardInput:executionContext:]_block_invoke_2 + 256
16 UIKit 0x18f431fac -[UIKeyboardTaskEntry execute:] + 192
17 UIKit 0x18e7975f0 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 384
18 Foundation 0x185baf2e4 __NSThreadPerformPerform + 340
19 CoreFoundation 0x18515b77c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
20 CoreFoundation 0x18515b6fc __CFRunLoopDoSource0 + 88
21 CoreFoundation 0x18515af84 __CFRunLoopDoSources0 + 204
22 CoreFoundation 0x185158b5c __CFRunLoopRun + 1048
23 CoreFoundation 0x185078c58 CFRunLoopRunSpecific + 436
24 GraphicsServices 0x186f24f84 GSEventRunModal + 100
25 UIKit 0x18e7d15c4 UIApplicationMain + 236
26 Q App 0x1050b756c main (main.m:16)
27 libdyld.dylib 0x184b9856c start + 4
As my crash reports, I didn't use NotificationCenter/observer in that screen. But the crash reports are showing in the NotificationCenter. Please Any know the solution for this ?
Note: The following is without knowing all required details because you did not provide any source code on how you implemented the feature nor does the crash report shown here contain any information about the exception code/signal being thrown.
The top frame shows the method objc_msgSend being invoked. This method is always used when the runtime tries to send a message (method) to an object. And crashes in this method usually mean the object doesn't exist any longer which means it was deallocated but your code still holds a reference.
So this looks like a memory management issue in your code. Without your actual implementation it is impossible to provide any meaningful help.
The best way to debug this is to run the app in debug mode and the device attached to Xcode and get more details. The Instrument tools can also help finding out where the problem is.

iOS app crashing in release but not in development and Swift symbols are not resolved

My app is working perfectly fine in development but switching to production / AdHoc release it crashes on the transition to the third UIViewController of my application flow.
Between the build there shouldn't be any difference. I have retrieved the log from the Devices window:
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x00000001000d49ac
Triggered by Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 MYAPP 0x00000001000d49ac 0x100010000 + 805292
1 UIKit 0x00000001868a8954 -[UIViewController loadViewIfRequired] + 688
2 UIKit 0x00000001868a8664 -[UIViewController view] + 28
3 UIKit 0x0000000186f9c1cc -[_UIFullscreenPresentationController _setPresentedViewController:] + 72
4 UIKit 0x0000000186ba378c -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 116
5 UIKit 0x0000000186bbeb4c -[UIViewController _presentViewController:withAnimationController:completion:] + 1968
6 UIKit 0x0000000186bc0f64 __62-[UIViewController presentViewController:animated:completion:]_block_invoke + 116
7 UIKit 0x0000000186995c48 -[UIViewController presentViewController:animated:completion:] + 212
8 MYAPP 0x0000000100090dcc 0x100010000 + 527820
9 MYAPP 0x0000000100090bd0 0x100010000 + 527312
10 PromiseKit 0x000000010032a9f4 0x1002e8000 + 272884
11 PromiseKit 0x00000001002ee820 0x1002e8000 + 26656
12 libdispatch.dylib 0x00000001936c1990 _dispatch_call_block_and_release + 20
13 libdispatch.dylib 0x00000001936c1950 _dispatch_client_callout + 12
14 libdispatch.dylib 0x00000001936c6208 _dispatch_main_queue_callback_4CF + 1604
15 CoreFoundation 0x00000001820522e8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
16 CoreFoundation 0x0000000182050390 __CFRunLoopRun + 1488
17 CoreFoundation 0x0000000181f7d1f0 CFRunLoopRunSpecific + 392
18 GraphicsServices 0x000000018b39f6f8 GSEventRunModal + 164
19 UIKit 0x000000018690e108 UIApplicationMain + 1484
20 MYAPP 0x00000001000be820 0x100010000 + 714784
21 libdyld.dylib 0x00000001936eea04 start + 0
What is bugging me:
There is a clear inconsistency between the environments I am working on.
The calls from MYAPP doesn't seem to be linked to any component / method call. I'm working with Swift maybe it does cause problem to resolve symbols. Which could make sense since PromiseKit calls are also unresolved.
I have no idea about how to debug this, not even about how to put log everywhere (because I wouldn't know how to get them).
Any help is welcome!
In Build settings, try changing Swift compiler -> Optimization Level -> Release to None. There's still a bug where sometimes the compiler messes up closures when optimizations are on. Maybe that's what's happening to you.

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

[UIView(CALayer Delegate) drawLayer:inContext: crash

my app crash in [UIView(CALayer Delegate) drawLayer:inContext: ,the most difficult is there are not any code of my app in the crash log and i cannot reproduce it .This issue cost me several days and I still have no idea. Any ideas you guys provide, I will try. Thank you for your help.
crash log:
0 libobjc.A.dylib objc_msgSend_stret (in libobjc.A.dylib) + 18
1 UIKit -[UIView(CALayerDelegate) drawLayer:inContext:]
2 QuartzCore -[CALayer drawInContext:] (in QuartzCore) + 116
3 QuartzCore CABackingStoreUpdate_ (in QuartzCore) + 1782
4 QuartzCore CA::Layer::display_() (in QuartzCore) + 972
5 QuartzCore CA::Layer::display() (in QuartzCore) + 128
6 QuartzCore CA::Layer::display_if_needed(CA::Transaction*) (in QuartzCore)
7 QuartzCore CA::Context::commit_transaction(CA::Transaction*)
8 QuartzCore CA::Transaction::commit() (in QuartzCore) + 314
9 QuartzCore CA::Transaction::pop() (in QuartzCore) + 126
10 QuartzCore +[CATransaction commit] (in QuartzCore) + 34
11 UIKit _UIWindowUpdateVisibleContextOrder (in UIKit) + 188
12 UIKit +[UIWindow _prepareWindowsForAppResume] (in UIKit) + 10
13 UIKit -[UIApplication _handleApplicationResumeEvent:] (in UIKit) + 74
14 UIKit -[UIApplication handleEvent:withNewEvent:] (in UIKit) + 1080
15 UIKit -[UIApplication sendEvent:] (in UIKit) + 54
16 UIKit _UIApplicationHandleEvent (in UIKit) + 5808
The solution is the try and sectionalize the problem. Assuming you have one view that is causing this, then the most likely explanation is that something in the view is corrupt or has been released.
1) Did you try turning on Zombies, to see if some dealloc'd item is getting messaged?
2) In the view that is showing (or about to show) when the crash starts, either remove items one at a time, or remove them all from the view, and start adding them one by one. A good way to do this type of messy works is just copy your project folder, save the old one, and go cut chunks of code out so you can get to a working point.
My guess is that something is getting released before it should.

Resources