Title:
SIGTRAP Crash in QuartzCore/CALayer during UI Lifecycle Changes
Description:
My app is experiencing occasional crashes triggered by a SIGTRAP signal during UI transitions (e.g., scene lifecycle changes, animations). The crash occurs in QuartzCore/UIKitCore code paths, and no business logic appears in the stack trace.
Crash Context:
Crash occurs sporadically during UI state changes (e.g., app backgrounding, view transitions).
Stack trace involves pthread_mutex_destroy, CA::Layer::commit_if_needed, and UIKit scene lifecycle methods.
Full crash log snippet:
Signal: SIGTRAP
Thread 0 Crashed:
0 libsystem_platform.dylib 0x... [symbol: _platform_memset$VARIANT$Haswell]
2 libsystem_pthread.dylib pthread_mutex_destroy + 64
3 QuartzCore CA::Layer::commit_if_needed(...)
4 UIKitCore UIScenePerformActionsWithLifecycleActionMask + 112
5 CoreFoundation _CFXNotificationPost + 736
Suspected Causes:
Threading Issue: Potential race condition in pthread_mutex destruction (e.g., mutex used after free).
UI Operation on Background Thread: CALayer/UIKit operations not confined to the main thread.
Lifecycle Mismatch: Scene/UI updates after deallocation (e.g., notifications triggering late UI changes).
Troubleshooting Attempted:
Enabled Zombie Objects – no obvious over-released objects detected.
Thread Sanitizer shows no clear data races.
Verified UIKit/CoreAnimation operations are dispatched to MainThread.
Request for Guidance:
Are there known issues with CA::Layer::commit_if_needed and scene lifecycle synchronization?
How to debug SIGTRAP in system frameworks when no app code is in the stack?
Recommended tools/approaches to isolate the mutex destruction issue.