iOS 18.1 crash UIHostingView.layoutSubviews() / swift_unknownObjectWeakAssign / objc_storeWeak

We're seeing sporadic crashes on devices running iOS 18.1 - both beta and release builds (22B83). The stack trace is always identical, a snippet of it below. As you can tell from the trace, it's happening in places we embed SwiftUI into UIKit via UIHostingController.

Anyone else seeing this?

4 libobjc.A.dylib 0xbe2c _objc_fatalv(unsigned long long, unsigned long long, char const*, char*) + 30

5 libobjc.A.dylib 0xb040 weak_register_no_lock + 396

6 libobjc.A.dylib 0xac50 objc_storeWeak + 472

7 libswiftCore.dylib 0x43ac34 swift_unknownObjectWeakAssign + 24

8 SwiftUI 0xeb74c8 _UIHostingView.base.getter + 160

9 SwiftUI 0x92124 _UIHostingView.layoutSubviews() + 112

10 SwiftUI 0x47860 @objc _UIHostingView.layoutSubviews() + 36

Take a look at the documentation for debugging techniques that has guidance on debugging common reasons for a crash. If you get stuck, let us know what you tried, and attach the fully symbolicated Apple crash report in your reply. Posting a Crash Report explains how to do so.

Full stack trace attached. Haven't been able to reproduce. This is a widespread issue across our app. Again, only seeing on iOS 18.1, no other iOS versions.

# Crashlytics - Stack trace
# Application: com.organization.myapp
# Platform: apple
# Version: 2024.10.3 (12875)
# Date: Fri Nov 08 2024 19:55:04 GMT-0500 (Eastern Standard Time)

Crashed: com.apple.main-thread
0  libsystem_kernel.dylib         0x13ec4 __abort_with_payload + 8
1  libsystem_kernel.dylib         0x33bec abort_with_payload_wrapper_internal + 104
2  libsystem_kernel.dylib         0x33b84 abort_with_payload_wrapper_internal + 30
3  libobjc.A.dylib                0xbea0 _objc_fatalv(unsigned long long, unsigned long long, char const*, char*) + 116
4  libobjc.A.dylib                0xbe2c _objc_fatalv(unsigned long long, unsigned long long, char const*, char*) + 30
5  libobjc.A.dylib                0xb040 weak_register_no_lock + 396
6  libobjc.A.dylib                0xac50 objc_storeWeak + 472
7  libswiftCore.dylib             0x43ac34 swift_unknownObjectWeakAssign + 24
8  SwiftUI                        0xeb74c8 _UIHostingView.base.getter + 160
9  SwiftUI                        0x92124 _UIHostingView.layoutSubviews() + 112
10 SwiftUI                        0x47860 @objc _UIHostingView.layoutSubviews() + 36
11 UIKitCore                      0xd688 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2424
12 QuartzCore                     0x78c28 CA::Layer::layout_if_needed(CA::Transaction*) + 496
13 QuartzCore                     0x787b4 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 148
14 QuartzCore                     0xcf914 CA::Context::commit_transaction(CA::Transaction*, double, double*) + 472
15 QuartzCore                     0x4e7c4 CA::Transaction::commit() + 648
16 QuartzCore                     0x91a0c CA::Transaction::flush_as_runloop_observer(bool) + 88
17 UIKitCore                      0xa3568 _UIApplicationFlushCATransaction + 52
18 UIKitCore                      0xa0b64 __setupUpdateSequence_block_invoke_2 + 332
19 UIKitCore                      0xa09d8 _UIUpdateSequenceRun + 84
20 UIKitCore                      0xa0628 schedulerStepScheduledMainSection + 172
21 UIKitCore                      0xa159c runloopSourceCallback + 92
22 CoreFoundation                 0x56328 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
23 CoreFoundation                 0x562bc __CFRunLoopDoSource0 + 176
24 CoreFoundation                 0x53dc0 __CFRunLoopDoSources0 + 244
25 CoreFoundation                 0x52fbc __CFRunLoopRun + 840
26 CoreFoundation                 0x52830 CFRunLoopRunSpecific + 588
27 GraphicsServices               0x11c4 GSEventRunModal + 164
28 UIKitCore                      0x3d2eb0 -[UIApplication _run] + 816
29 UIKitCore                      0x4815b4 UIApplicationMain + 340
30 UIKitCore                      0x7bbfa8 block_destroy_helper.23 + 10212
31 My App                         0x68db9c main + 4351155100 (AppDelegate.swift:4351155100)

com.apple.uikit.eventfetch-thread
0  libsystem_kernel.dylib         0x1688 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x4d98 mach_msg2_internal + 80
2  libsystem_kernel.dylib         0x4cb0 mach_msg_overwrite + 424
3  libsystem_kernel.dylib         0x4afc mach_msg + 24
4  CoreFoundation                 0x53a84 __CFRunLoopServiceMachPort + 160
5  CoreFoundation                 0x53130 __CFRunLoopRun + 1212
6  CoreFoundation                 0x52830 CFRunLoopRunSpecific + 588
7  Foundation                     0xb7500 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212
8  Foundation                     0xb7350 -[NSRunLoop(NSRunLoop) runUntilDate:] + 64
9  UIKitCore                      0x3e6358 -[UIEventFetcher threadMain] + 420
10 Foundation                     0xc86c8 __NSThread__start__ + 724
11 libsystem_pthread.dylib        0x637c _pthread_start + 136
12 libsystem_pthread.dylib        0x1494 thread_start + 8

com.google.firebase.crashlytics.MachExceptionServer
0  libsystem_kernel.dylib         0x1688 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x4d98 mach_msg2_internal + 80
2  libsystem_kernel.dylib         0x4cb0 mach_msg_overwrite + 424
3  libsystem_kernel.dylib         0x4afc mach_msg + 24
4  My App                         0x8e5278 FIRCLSMachExceptionServer + 196 (FIRCLSMachException.c:196)
5  libsystem_pthread.dylib        0x637c _pthread_start + 136
6  libsystem_pthread.dylib        0x1494 thread_start + 8

com.apple.CFSocket.private
0  libsystem_kernel.dylib         0x9234 select$DARWIN_EXTSN + 8
1  libsystem_kernel.dylib         0x9234 __select + 8
2  CoreFoundation                 0xbb95c __CFSocketManager + 704
3  libsystem_pthread.dylib        0x637c _pthread_start + 136
4  libsystem_pthread.dylib        0x1494 thread_start + 8

com.apple.NSURLConnectionLoader
0  libsystem_kernel.dylib         0x1688 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x4d98 mach_msg2_internal + 80
2  libsystem_kernel.dylib         0x4cb0 mach_msg_overwrite + 424
3  libsystem_kernel.dylib         0x4afc mach_msg + 24
4  CoreFoundation                 0x53a84 __CFRunLoopServiceMachPort + 160
5  CoreFoundation                 0x53130 __CFRunLoopRun + 1212
6  CoreFoundation                 0x52830 CFRunLoopRunSpecific + 588
7  CFNetwork                      0xfdee0 +[__CFN_CoreSchedulingSetRunnable _run:] + 416
8  Foundation                     0xc86c8 __NSThread__start__ + 724
9  libsystem_pthread.dylib        0x637c _pthread_start + 136
10 libsystem_pthread.dylib        0x1494 thread_start + 8

Thread
0  libsystem_kernel.dylib         0x1410 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x4cc8 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0x1488 start_wqthread + 8

Thread
0  libsystem_kernel.dylib         0x1410 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x4cc8 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0x1488 start_wqthread + 8

Thread
0  libsystem_kernel.dylib         0x1410 __workq_kernreturn + 8
1  libsystem_pthread.dylib        0x4cc8 _pthread_wqthread + 364
2  libsystem_pthread.dylib        0x1488 start_wqthread + 8

Thread
0  libsystem_pthread.dylib        0x1480 start_wqthread + 9100706942

Thread
0  libsystem_pthread.dylib        0x1480 start_wqthread + 9100706942

com.apple.SwiftUI.AsyncRenderer
0  libsystem_kernel.dylib         0x1688 mach_msg2_trap + 8
1  libsystem_kernel.dylib         0x4d98 mach_msg2_internal + 80
2  libsystem_kernel.dylib         0x4cb0 mach_msg_overwrite + 424
3  libsystem_kernel.dylib         0x4afc mach_msg + 24
4  CoreFoundation                 0x53a84 __CFRunLoopServiceMachPort + 160
5  CoreFoundation                 0x53130 __CFRunLoopRun + 1212
6  CoreFoundation                 0x52830 CFRunLoopRunSpecific + 588
7  Foundation                     0xb7500 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212
8  Foundation                     0xb73d4 -[NSRunLoop(NSRunLoop) run] + 64
9  SwiftUI                        0x8f51f4 specialized static DisplayLink.asyncThread(arg:) + 792
10 SwiftUI                        0x8f4558 @objc static DisplayLink.asyncThread(arg:) + 72
11 Foundation                     0xc86c8 __NSThread__start__ + 724
12 libsystem_pthread.dylib        0x637c _pthread_start + 136
13 libsystem_pthread.dylib        0x1494 thread_start + 8

We're seeing similar crashes - we recently converted two of our main pages to SwiftUI to be embedded inside UIHostingControllers (root hierarchy is still UIKit based), and we are seeing this crash since rollout. Not sure if we are doing something wrong, but we are only seeing this crash on iOS 18.1+. We support iOS 14+

Continuing to see this issue - any other details I can provide you?

We just started rolling out an update to our users - we most likely had a race condition with data being updated twice shortly after each other, which caused this crash.

We're not (yet) seeing the crash on our latest rollout. The last version is also when we introduced that bug, so it seems they are related.

It's weird that it only happens to iOS 18.1+ users, but I guess it must be related to something SwiftUI changed under the hood ¯\_(ツ)_/¯

This is happening in iOS 18.2 as well now.

is there anymore information I can provide? This crash is still affecting our users. We embed our SwiftUI in a very standard, vanilla way via UIHostingController. This crash appeared after the release of 18.1, with zero changes to our codebase.

iOS 18.1 crash UIHostingView.layoutSubviews() / swift_unknownObjectWeakAssign / objc_storeWeak
 
 
Q