SwiftUI AttributeGraph crash on launch (rare)

Viewed 444

My app in TestFlight has a few times crashed on launch, and when it decides to crash it will do so on every launch afterwards. Only way to fix it, is to reinstall the app, and then in a future time it will crash again, so I have no idea how to reproduce the crash.

I have the crash log, but I am unsure what to read from it. The app is pure SwiftUI.

Incident Identifier: 643EF787-991A-41DD-98C9-CFFCEA4C8982
CrashReporter Key:   8eb3731ae5012452a0a5758baaacba1a94696953
Hardware Model:      iPhone12,3
Process:             TimeMindster [5006]
Path:                /private/var/containers/Bundle/Application/99C55F69-E5DA-47CF-BC59-CBC20965489F/TimeMindster.app/TimeMindster
Identifier:          com.magnuskahr.TimeMindster
Version:             12 (1.0)
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           com.magnuskahr.TimeMindster [1341]


Date/Time:           2021-04-28 21:14:04.6293 +0200
Launch Time:         2021-04-28 21:14:04.0304 +0200
OS Version:          iPhone OS 14.5 (18E199)
Release Type:        User
Baseband Version:    2.04.07
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Triggered by Thread:  0

Application Specific Information:
abort() called

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_kernel.dylib          0x00000001b3a3f334 __pthread_kill + 8
1   libsystem_pthread.dylib         0x00000001d1461aa0 pthread_kill + 272
2   libsystem_c.dylib               0x000000018edc6b90 abort + 104
3   AttributeGraph                  0x00000001aee71a6c util::Heap::Heap+ 121452 (void*, unsigned long, unsigned long) + 0
4   AttributeGraph                  0x00000001aee5f4cc AG::Graph::any_inputs_changed+ 46284 (AG::data::ptr<AG::Node>, unsigned int const*, unsigned long) + 0
5   AttributeGraph                  0x00000001aee7109c AGGraphGetValue + 232
6   SwiftUI                         0x000000018c450344 MergePreferenceKeys.rhs.getter + 32
7   SwiftUI                         0x000000018c450394 MergePreferenceKeys.value.getter + 52
8   SwiftUI                         0x000000018c0ecf64 specialized implicit closure #2 in implicit closure #1 in closure #1 in closure #1 in Attribute.init<A>+ 1949540 (_:) + 36
9   SwiftUI                         0x000000018c148490 partial apply for specialized implicit closure #2 in implicit closure #1 in closure #1 in closure #1 in Attribute.init<A>+ 2323600 (_:) + 48
10  AttributeGraph                  0x00000001aee5977c AG::Graph::UpdateStack::update+ 22396 () + 492
11  AttributeGraph                  0x00000001aee59bb4 AG::Graph::update_attribute+ 23476 (AG::data::ptr<AG::Node>, bool) + 332
12  AttributeGraph                  0x00000001aee5f2fc AG::Graph::input_value_ref_slow+ 45820 (AG::data::ptr<AG::Node>, AG::AttributeID, unsigned int, AGSwiftMetadata const*, bool*, long) + 364
13  AttributeGraph                  0x00000001aee7109c AGGraphGetValue + 232
14  SwiftUI                         0x000000018c0bbd00 specialized HostPreferencesWriter.updateValue+ 1748224 () + 136
15  SwiftUI                         0x000000018c10c5ac partial apply for specialized implicit closure #2 in implicit closure #1 in closure #1 in closure #1 in Attribute.init<A>+ 2078124 (_:) + 24
16  AttributeGraph                  0x00000001aee5977c AG::Graph::UpdateStack::update+ 22396 () + 492
17  AttributeGraph                  0x00000001aee59bb4 AG::Graph::update_attribute+ 23476 (AG::data::ptr<AG::Node>, bool) + 332
18  AttributeGraph                  0x00000001aee5f2fc AG::Graph::input_value_ref_slow+ 45820 (AG::data::ptr<AG::Node>, AG::AttributeID, unsigned int, AGSwiftMetadata const*, bool*, long) + 364
19  AttributeGraph                  0x00000001aee7109c AGGraphGetValue + 232
20  SwiftUI                         0x000000018c0bbcd8 specialized HostPreferencesWriter.updateValue+ 1748184 () + 96
21  SwiftUI                         0x000000018c10c5ac partial apply for specialized implicit closure #2 in implicit closure #1 in closure #1 in closure #1 in Attribute.init<A>+ 2078124 (_:) + 24
22  AttributeGraph                  0x00000001aee5977c AG::Graph::UpdateStack::update+ 22396 () + 492
23  AttributeGraph                  0x00000001aee59bb4 AG::Graph::update_attribute+ 23476 (AG::data::ptr<AG::Node>, bool) + 332
24  AttributeGraph                  0x00000001aee5f2fc AG::Graph::input_value_ref_slow+ 45820 (AG::data::ptr<AG::Node>, AG::AttributeID, unsigned int, AGSwiftMetadata const*, bool*, long) + 364
25  AttributeGraph                  0x00000001aee7109c AGGraphGetValue + 232
26  SwiftUI                         0x000000018c0bbcd8 specialized HostPreferencesWriter.updateValue+ 1748184 () + 96
27  SwiftUI                         0x000000018c10c5ac partial apply for specialized implicit closure #2 in implicit closure #1 in closure #1 in closure #1 in Attribute.init<A>+ 2078124 (_:) + 24
28  AttributeGraph                  0x00000001aee5977c AG::Graph::UpdateStack::update+ 22396 () + 492
29  AttributeGraph                  0x00000001aee59bb4 AG::Graph::update_attribute+ 23476 (AG::data::ptr<AG::Node>, bool) + 332
30  AttributeGraph                  0x00000001aee5f2fc AG::Graph::input_value_ref_slow+ 45820 (AG::data::ptr<AG::Node>, AG::AttributeID, unsigned int, AGSwiftMetadata const*, bool*, long) + 364
31  AttributeGraph                  0x00000001aee7109c AGGraphGetValue + 232
32  SwiftUI                         0x000000018c2b8ecc DynamicPreferenceCombiner.value.getter + 1028
33  SwiftUI                         0x000000018c1a3144 implicit closure #2 in implicit closure #1 in closure #1 in closure #1 in Attribute.init<A>+ 2695492 (_:) + 252
34  AttributeGraph                  0x00000001aee5977c AG::Graph::UpdateStack::update+ 22396 () + 492
35  AttributeGraph                  0x00000001aee59bb4 AG::Graph::update_attribute+ 23476 (AG::data::ptr<AG::Node>, bool) + 332
36  AttributeGraph                  0x00000001aee5ed6c AG::Graph::value_ref+ 44396 (AG::AttributeID, AGSwiftMetadata const*, bool*) + 156
37  AttributeGraph                  0x00000001aee710e4 AGGraphGetValue + 304
38  SwiftUI                         0x000000018c97649c GraphHost.updatePreferences+ 10900636 () + 56
39  SwiftUI                         0x000000018c3fd188 ViewGraph.updateOutputs+ 5161352 (at:) + 112
40  SwiftUI                         0x000000018c8c1688 closure #1 in ViewRendererHost.render+ 10159752 (interval:updateDisplayList:) + 1508
41  SwiftUI                         0x000000018c8b7bdc ViewRendererHost.render+ 10120156 (interval:updateDisplayList:) + 308
42  SwiftUI                         0x000000018c2cc72c closure #1 in _UIHostingView.requestImmediateUpdate+ 3913516 () + 72
43  SwiftUI                         0x000000018ca4d89c thunk for @escaping @callee_guaranteed () -> + 11782300 () + 28
44  libdispatch.dylib               0x0000000185631a54 _dispatch_call_block_and_release + 32
45  libdispatch.dylib               0x00000001856337ec _dispatch_client_callout + 20
46  libdispatch.dylib               0x0000000185641c40 _dispatch_main_queue_callback_4CF + 884
47  CoreFoundation                  0x00000001859c01f8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
48  CoreFoundation                  0x00000001859ba0d0 __CFRunLoopRun + 2524
49  CoreFoundation                  0x00000001859b91c0 CFRunLoopRunSpecific + 600
50  GraphicsServices                0x000000019cfa1734 GSEventRunModal + 164
51  UIKitCore                       0x00000001884277e4 -[UIApplication _run] + 1072
52  UIKitCore                       0x000000018842d054 UIApplicationMain + 168
53  SwiftUI                         0x000000018c8fd350 closure #1 in KitRendererCommon+ 10404688 (_:) + 112
54  SwiftUI                         0x000000018c8fd2dc runApp<A>+ 10404572 (_:) + 224
55  SwiftUI                         0x000000018c3f5b4c static App.main+ 5131084 () + 144
56  TimeMindster                    0x000000010230dce0 0x102294000 + 498912
57  TimeMindster                    0x000000010230dd80 0x102294000 + 499072
58  libdyld.dylib                   0x0000000185675cf8 start + 4

Thread 1:
0   libsystem_pthread.dylib         0x00000001d1469744 start_wqthread + 0

Thread 2:
0   libsystem_pthread.dylib         0x00000001d1469744 start_wqthread + 0

Thread 3 name:  Dispatch queue: com.apple.root.utility-qos
Thread 3:
0   libswiftCore.dylib              0x000000018994b154 swift_conformsToProtocolImpl(swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*)::$_5::operator()((anonymous namespace)::ConformanceSection const&) const::'lambda'(swift::TargetProtocolConformanceDescriptor<swift::InProcess> const&)::operator()+ 3895636 (swift::TargetProtocolConformanceDescriptor<swift::InProcess> const&) const + 40
1   libswiftCore.dylib              0x000000018994a344 swift_conformsToProtocolImpl+ 3892036 (swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*) + 596
2   libswiftCore.dylib              0x000000018994a344 swift_conformsToProtocolImpl+ 3892036 (swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*) + 596
3   AttributeGraph                  0x00000001aee65d2c AG::LayoutDescriptor::Builder::visit_element+ 73004 (AG::swift::metadata const*, AG::swift::metadata::ref_kind, unsigned long) + 212
4   AttributeGraph                  0x00000001aee576d4 AG::swift::metadata_visitor::visit_field+ 14036 (AG::swift::metadata const*, AG::swift::field_record const&, unsigned long) + 96
5   AttributeGraph                  0x00000001aee56e64 AG::swift::metadata::visit+ 11876 (AG::swift::metadata_visitor&) const + 820
6   AttributeGraph                  0x00000001aee660e8 AG::LayoutDescriptor::Builder::visit_case+ 73960 (AG::swift::metadata const*, AG::swift::field_record const&, unsigned int) + 376
7   AttributeGraph                  0x00000001aee56de0 AG::swift::metadata::visit+ 11744 (AG::swift::metadata_visitor&) const + 688
8   AttributeGraph                  0x00000001aee65e08 AG::LayoutDescriptor::Builder::visit_element+ 73224 (AG::swift::metadata const*, AG::swift::metadata::ref_kind, unsigned long) + 432
9   AttributeGraph                  0x00000001aee576d4 AG::swift::metadata_visitor::visit_field+ 14036 (AG::swift::metadata const*, AG::swift::field_record const&, unsigned long) + 96
10  AttributeGraph                  0x00000001aee56e64 AG::swift::metadata::visit+ 11876 (AG::swift::metadata_visitor&) const + 820
11  AttributeGraph                  0x00000001aee66bdc AG::LayoutDescriptor::make_layout+ 76764 (AG::swift::metadata const*, AGComparisonMode, AG::LayoutDescriptor::HeapMode) + 624
12  AttributeGraph                  0x00000001aee67eb4 AG::(anonymous namespace)::LayoutCache::drain_queue+ 81588 (void*) + 152
13  libdispatch.dylib               0x00000001856337ec _dispatch_client_callout + 20
14  libdispatch.dylib               0x00000001856450dc _dispatch_root_queue_drain + 688
15  libdispatch.dylib               0x00000001856457a8 _dispatch_worker_thread2 + 112
16  libsystem_pthread.dylib         0x00000001d1462768 _pthread_wqthread + 216
17  libsystem_pthread.dylib         0x00000001d146974c start_wqthread + 8

Thread 4:
0   libsystem_pthread.dylib         0x00000001d1469744 start_wqthread + 0

Thread 5:
0   libsystem_pthread.dylib         0x00000001d1469744 start_wqthread + 0

Thread 6 name:  com.apple.uikit.eventfetch-thread
Thread 6:
0   libsystem_kernel.dylib          0x00000001b3a1a4fc mach_msg_trap + 8
1   libsystem_kernel.dylib          0x00000001b3a19884 mach_msg + 76
2   CoreFoundation                  0x00000001859bfd10 __CFRunLoopServiceMachPort + 372
3   CoreFoundation                  0x00000001859b9bb0 __CFRunLoopRun + 1212
4   CoreFoundation                  0x00000001859b91c0 CFRunLoopRunSpecific + 600
5   Foundation                      0x0000000186c99fac -[NSRunLoop+ 32684 (NSRunLoop) runMode:beforeDate:] + 232
6   Foundation                      0x0000000186c99e78 -[NSRunLoop+ 32376 (NSRunLoop) runUntilDate:] + 92
7   UIKitCore                       0x00000001884dc38c -[UIEventFetcher threadMain] + 516
8   Foundation                      0x0000000186e0b2fc __NSThread__start__ + 864
9   libsystem_pthread.dylib         0x00000001d1460c00 _pthread_start + 320
10  libsystem_pthread.dylib         0x00000001d1469758 thread_start + 8

Thread 7:
0   libsystem_pthread.dylib         0x00000001d1469744 start_wqthread + 0

Thread 8:
0   libsystem_pthread.dylib         0x00000001d1469744 start_wqthread + 0

Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000000   x1: 0x0000000000000000   x2: 0x0000000000000000   x3: 0x0000000000000000
    x4: 0x00000000000062dc   x5: 0x000000000000000b   x6: 0x000000000000000a   x7: 0x000000000000003e
    x8: 0x6f2c18735f2b4680   x9: 0x6f2c18725da73e40  x10: 0x00000000000007fd  x11: 0x000000000000005e
   x12: 0x0000000000000001  x13: 0x00000000d180105d  x14: 0x00000000d1a01800  x15: 0x0000000000001800
   x16: 0x0000000000000148  x17: 0x00000001028c78c0  x18: 0x000000011111fe1c  x19: 0x0000000000000006
   x20: 0x0000000000000103  x21: 0x00000001028c79a0  x22: 0x000000000001ca18  x23: 0x0000000000000000
   x24: 0x0000000000000000  x25: 0x000000000000f618  x26: 0x00000001e7f20950  x27: 0x0000000102b1d66c
   x28: 0x0000000102b0f418   fp: 0x000000016db69400   lr: 0x00000001d1461aa0
    sp: 0x000000016db693e0   pc: 0x00000001b3a3f334 cpsr: 0x40000000
   esr: 0x56000080  Address size fault
1 Answers

I had experienced same problem. It was caused by combination of AnyView and NSViewRepresentable wrapper for WKWebView. Getting rid of AnyView by rewriting helper function with @ViewBuilder fixed the problem.

Problem:

func viewFunc() -> AnyView {
  switch self {
    case .case1: return AnyView(ListOfWebViewWrappers())
    default:     return AnyView(WaitView())
  }
}

Solution:

@ViewBuilder
func viewFunc() -> some View {
  switch self {
    case .case1: ListOfWebViewWrappers()
    default:     WaitView()
  }
}

the @ViewBuilder allows SwiftUI to properly track each view's identity and properly manage resources. More information about view's identity: https://developer.apple.com/videos/play/wwdc2021/10022/

Related