A crash triggered by backgroud thread which is hard to catch, seems UI main thread updating issue.

Answered by DTS Engineer in 736108022

Consider this backtrace:

Thread 11 Crashed:
…
10  CoreAutoLayout          … _AssertAutoLayoutOnAllowedThreadsOnly + 328
11  CoreAutoLayout          … -[NSISEngine withBehaviors:performModifications:] + 36
12  UIKitCore               … -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1852
13  QuartzCore              … CA::Layer::layout_if_needed(CA::Transaction*) + 500
14  QuartzCore              … CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 148
15  QuartzCore              … CA::Context::commit_transaction(CA::Transaction*, double, double*) + 456
16  QuartzCore              … CA::Transaction::commit() + 652
17  QuartzCore              … CA::Transaction::release_thread(void*) + 228
18  libsystem_pthread.dylib … _pthread_tsd_cleanup + 620
19  libsystem_pthread.dylib … _pthread_exit + 84
20  libsystem_pthread.dylib … _pthread_wqthread_exit + 76
21  libsystem_pthread.dylib … _pthread_wqthread + 424
22  libsystem_pthread.dylib … start_wqthread + 8

Auto layout is crashing your app because of a threading problem. In general our UI frameworks are main-thread-only, but there’s a specific exception for the auto layout engine. It’s not completely thread safe but it can be used from multiple threads in very limited circumstances. Something about your app is causing it to be used outside of those circumstances, and that’s why you’re crashing.

As to what that is, it’s hard to say. That’s partly because I’m not an expert on auto layout [1] and partly because the crash report doesn’t collect all the info required to debug this. If you ever manage to reproduce this locally, immediately trigger a sysdiagnose log and that might capture more actionable info.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] I’ve added more tags to your thread in the hope that such experts might chime in.

could anyone explain how to find the cause from my own code from this? as I could not find connections. Or I missed some configurations for the crash report... thanks.

Accepted Answer

Consider this backtrace:

Thread 11 Crashed:
…
10  CoreAutoLayout          … _AssertAutoLayoutOnAllowedThreadsOnly + 328
11  CoreAutoLayout          … -[NSISEngine withBehaviors:performModifications:] + 36
12  UIKitCore               … -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1852
13  QuartzCore              … CA::Layer::layout_if_needed(CA::Transaction*) + 500
14  QuartzCore              … CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 148
15  QuartzCore              … CA::Context::commit_transaction(CA::Transaction*, double, double*) + 456
16  QuartzCore              … CA::Transaction::commit() + 652
17  QuartzCore              … CA::Transaction::release_thread(void*) + 228
18  libsystem_pthread.dylib … _pthread_tsd_cleanup + 620
19  libsystem_pthread.dylib … _pthread_exit + 84
20  libsystem_pthread.dylib … _pthread_wqthread_exit + 76
21  libsystem_pthread.dylib … _pthread_wqthread + 424
22  libsystem_pthread.dylib … start_wqthread + 8

Auto layout is crashing your app because of a threading problem. In general our UI frameworks are main-thread-only, but there’s a specific exception for the auto layout engine. It’s not completely thread safe but it can be used from multiple threads in very limited circumstances. Something about your app is causing it to be used outside of those circumstances, and that’s why you’re crashing.

As to what that is, it’s hard to say. That’s partly because I’m not an expert on auto layout [1] and partly because the crash report doesn’t collect all the info required to debug this. If you ever manage to reproduce this locally, immediately trigger a sysdiagnose log and that might capture more actionable info.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] I’ve added more tags to your thread in the hope that such experts might chime in.

Thank you @eskimo! Unfortunately, I could not reproduce it by triggering a sysdiagnose log, could you give me a hint on how to involve a sysdiagnose log? Yesterday I got another crash report due to probably the same reason but with a little difference in the backtrace, the report is attached.

Is my understanding correct that I should generally use DispatchQueue.main.async {} for all the possible background threads/tasks which update UI?

Unfortunately, I could not reproduce it by triggering a sysdiagnose log

Ah, that’s the reverse of what I was suggesting. Rather, my advice was to test your app until it crashes and then immediately trigger a sysdiagnose log to see if that captures more useful info.

Of course, this assumes that you can reproduce the problem, and it sounds like that’s not the case.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

@samliu_QPA, I'm receiving the same crashes and can not reproduce them. Have you found a solution to fix this or can give me any hint to find the root cause?

@Rumio, I haven't received the same crash as this again, the root cause is still not clear to me. An extra thing I did after the last crash was to add DispatchQueue.main.async {} to all potential codes which update UI outside of the main thread, so the root fault will still be latent until I get another same crash...or what was happening in 'auto layout' regarding this crash can be figured out...

A crash triggered by backgroud thread which is hard to catch, seems UI main thread updating issue.
 
 
Q