SwiftUI crashing with EXC_BREAKPOINT (SIGTRAP) for one user and I can't replicate it in simulator

Viewed 1449

I taught myself to code this year and finally started sharing my app with some friends through TestFlight. One friend of mine can't tap anything in the app without it crashing, but I can't seem to replicate the issue in simulator. Here's the crash log:

Incident Identifier: 9C5CBC92-D799-4EF7-A0BD-B3D38BDFCD6A
Beta Identifier:     14981E01-C6E4-4340-A6C2-2C7730C5F39F
Hardware Model:      iPhone9,3
Process:             Skool [849]
Path:                /private/var/containers/Bundle/Application/CD824E3B-BB88-47D1-912E-55156C40187E/Skool.app/Skool
Identifier:          com.kevinolmats.Skool
Version:             2777 (0.2.2)
AppStoreTools:       11E503a
AppVariant:          1:iPhone9,3:13
Beta:                YES
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           com.kevinolmats.Skool [677]


Date/Time:           2020-05-09 10:19:43.2873 -0600
Launch Time:         2020-05-09 10:19:41.3463 -0600
OS Version:          iPhone OS 13.4.1 (17E262)
Release Type:        User
Baseband Version:    4.02.02
Report Version:      104

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x00000001becb85e0
Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5
Terminating Process: exc handler [849]
Triggered by Thread:  0

Thread 0 name:
Thread 0 Crashed:
0   libswiftCore.dylib              0x00000001becb85e0 _assertionFailure(_:_:file:line:flags:) + 796 (AssertCommon.swift:132)
1   libswiftCore.dylib              0x00000001becb85e0 _assertionFailure(_:_:file:line:flags:) + 796 (AssertCommon.swift:132)
2   SwiftUI                         0x00000001e9394268 EnvironmentObject.error() + 216 (EnvironmentObject.swift:55)
3   Skool                           0x0000000104223228 CourseAssignmentsListView.body.getter + 2116 (CourseAssignmentsListView.swift:0)
4   SwiftUI                         0x00000001e8ef4a40 DynamicPropertyBody.update(context:) + 1788 (CustomView.swift:110)
5   SwiftUI                         0x00000001e8ef5040 protocol witness for static UntypedAttribute._update(_:graph:attribute:) in conformance DynamicPr... + 36 (<compiler-generated>:0)
6   AttributeGraph                  0x00000001dd21e998 partial apply + 28 (<compiler-generated>:0)
7   AttributeGraph                  0x00000001dd2079fc AG::Graph::UpdateStack::update() + 440 (ag-closure.h:104)
8   AttributeGraph                  0x00000001dd207eb4 AG::Graph::update_attribute(unsigned int, bool) + 372 (ag-graph-update.cc:399)
9   AttributeGraph                  0x00000001dd20b044 AG::Graph::value_ref(AG::attribute_t, AGTypeID, bool*) + 116 (ag-graph.cc:762)
10  AttributeGraph                  0x00000001dd218310 AGGraphGetValue + 48 (AGGraph.mm:304)
11  SwiftUI                         0x00000001e8ff59a0 ViewGraph.accessibilityNodes() + 108 (<compiler-generated>:0)
12  SwiftUI                         0x00000001e93adf08 specialized _UIHostingView.enableAccessibility() + 116
13  SwiftUI                         0x00000001e93a4aac specialized _UIHostingView.init(rootView:) + 2116 (UIHostingView.swift:1278)
14  SwiftUI                         0x00000001e93b3dc8 specialized UIHostingController.init(rootView:) + 56 (UIHostingView.swift:0)
15  SwiftUI                         0x00000001e933df74 specialized DestinationHostingController.__allocating_init(rootView:) + 56 (<compiler-generated>:0)
16  SwiftUI                         0x00000001e933dd2c NavigationBridge_PhoneTV.push(_:onto:animated:) + 76 (NavigationBridge_PhoneTV.swift:84)
17  SwiftUI                         0x00000001e8f83438 UIKitNavigationBridge.updatePresentedContent(_:animated:) + 204 (UIKitNavigationBridge.swift:168)
18  SwiftUI                         0x00000001e8f83844 UIKitNavigationBridge.preferencesDidChange(_:) + 372 (UIKitNavigationBridge.swift:203)
19  SwiftUI                         0x00000001e933d560 NavigationBridge_PhoneTV.preferencesDidChange(_:) + 44 (NavigationBridge_PhoneTV.swift:21)
20  SwiftUI                         0x00000001e8f26078 _UIHostingView.preferencesDidChange() + 476 (_UIHostingView.swift:199)
21  SwiftUI                         0x00000001e8ff3d74 ViewGraph.updateOutputs(at:) + 180 (ViewGraph.swift:652)
22  SwiftUI                         0x00000001e92928b4 closure #1 in closure #1 in ViewRendererHost.render(interval:updateDisplayList:) + 816 (ViewRendererHost.swift:157)
23  SwiftUI                         0x00000001e9291d54 closure #1 in ViewRendererHost.render(interval:updateDisplayList:) + 524 (ViewRendererHost.swift:145)
24  SwiftUI                         0x00000001e9288c5c ViewRendererHost.render(interval:updateDisplayList:) + 316 (ViewRendererHost.swift:132)
25  SwiftUI                         0x00000001e93aee50 _UIHostingView.displayLinkTimer(timestamp:) + 160 (UIHostingView.swift:1391)
26  SwiftUI                         0x00000001e8f26344 DisplayLink.displayLinkTimer(_:) + 88 (_UIHostingView.swift:270)
27  SwiftUI                         0x00000001e8f2639c @objc DisplayLink.displayLinkTimer(_:) + 40 (<compiler-generated>:0)
28  QuartzCore                      0x00000001b81c0368 CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 516 (CADisplay.mm:2528)
29  IOKit                           0x00000001b2751628 IODispatchCalloutFromCFMessage + 480 (IOKitLib.c:1239)
30  CoreFoundation                  0x00000001b1762bc0 __CFMachPortPerform + 172 (CFMachPort.c:533)
31  CoreFoundation                  0x00000001b178c200 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 56 (CFRunLoop.c:1937)
32  CoreFoundation                  0x00000001b178b90c __CFRunLoopDoSource1 + 444 (CFRunLoop.c:2075)
33  CoreFoundation                  0x00000001b17866c0 __CFRunLoopRun + 1888 (CFRunLoop.c:3098)
34  CoreFoundation                  0x00000001b1785c34 CFRunLoopRunSpecific + 424 (CFRunLoop.c:3192)
35  GraphicsServices                0x00000001bb8cf38c GSEventRunModal + 160 (GSEvent.c:2246)
36  UIKitCore                       0x00000001b58b822c UIApplicationMain + 1932 (UIApplication.m:4820)
37  Skool                           0x000000010417275c main + 68 (OverdueDashboardSubview.swift:13)
38  libdyld.dylib                   0x00000001b160d800 start + 4

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

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

Thread 3:
0   libsystem_pthread.dylib         0x00000001b1527738 start_wqthread + 0

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

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

Thread 6 name:
Thread 6:
0   libsystem_kernel.dylib          0x00000001b15e1198 mach_msg_trap + 8
1   libsystem_kernel.dylib          0x00000001b15e060c mach_msg + 72 (mach_msg.c:103)
2   CoreFoundation                  0x00000001b178b3b4 __CFRunLoopServiceMachPort + 148 (CFRunLoop.c:2575)
3   CoreFoundation                  0x00000001b17863e8 __CFRunLoopRun + 1160 (CFRunLoop.c:2931)
4   CoreFoundation                  0x00000001b1785c34 CFRunLoopRunSpecific + 424 (CFRunLoop.c:3192)
5   Foundation                      0x00000001b1ac8bcc -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 228 (NSRunLoop.m:374)
6   Foundation                      0x00000001b1ac8aac -[NSRunLoop(NSRunLoop) runUntilDate:] + 88 (NSRunLoop.m:421)
7   UIKitCore                       0x00000001b595a160 -[UIEventFetcher threadMain] + 152 (UIEventFetcher.m:736)
8   Foundation                      0x00000001b1bf79d0 __NSThread__start__ + 848 (NSThread.m:724)
9   libsystem_pthread.dylib         0x00000001b1523d98 _pthread_start + 156 (pthread.c:896)
10  libsystem_pthread.dylib         0x00000001b152774c thread_start + 8

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

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

Thread 9:
0   libsystem_pthread.dylib         0x00000001b1527738 start_wqthread + 0

Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000105d669e0   x1: 0x00000001bef56ef8   x2: 0x0000000000000407   x3: 0x000000000000001e
    x4: 0x0000000105d71c00   x5: 0x0000000000000013   x6: 0x0000000000000000   x7: 0x00000000000003f8
    x8: 0x0000000105d669e8   x9: 0x0000000200000002  x10: 0xfffffffe00000000  x11: 0x0000000000000000
   x12: 0x0000000000000002  x13: 0x0000000000003fff  x14: 0x000000004ca45cf5  x15: 0x000000000000f0be
   x16: 0x00000001b1512ffc  x17: 0x0000000001000002  x18: 0x0000000000000000  x19: 0x0000000105d669e0
   x20: 0x0000000000000000  x21: 0x0000000000000000  x22: 0x0000000000000000  x23: 0x00000001e94156a0
   x24: 0x0000000105d669e0  x25: 0xf000000000000095  x26: 0x000000000000000b  x27: 0x0000000000000002
   x28: 0x00000001042c7c58   fp: 0x000000016bc906a0   lr: 0x00000001becb85e0
    sp: 0x000000016bc90620   pc: 0x00000001becb85e0 cpsr: 0x60000000
   esr: 0xf2000001  Address size fault

I'm particularly concerned with this line:

37  Skool                           0x000000010417275c main + 68 (OverdueDashboardSubview.swift:13)

In the code, that line is:

@FetchRequest(entity: Assignment.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \Assignment.dueDate, ascending: true), NSSortDescriptor(keyPath: \Assignment.name, ascending: true)]) var assignments: FetchedResults<Assignment>

but this works perfectly fine for me and everyone else I've sent the beta to. Is there something I'm missing in the crash log? Like I said I'm pretty new to coding and even newer when it comes to reading logs like this. Any ideas would be much appreciated!

Edit: Here is the code for CourseAssignmentListView as requested:

struct CourseAssignmentsListView: View {
    @FetchRequest(entity: Assignment.entity(),
                  sortDescriptors: [NSSortDescriptor(keyPath: \Assignment.course?.name, ascending: true),
                                    NSSortDescriptor(keyPath: \Assignment.isDue, ascending: false),
                                    NSSortDescriptor(keyPath: \Assignment.dueDate, ascending: true),
                                    NSSortDescriptor(keyPath: \Assignment.name, ascending: true)]) var assignments: FetchedResults<Assignment>

    @EnvironmentObject var accentColor: AccentColorManager
    @Environment(\.managedObjectContext) var context

    @State var course: Course?
    @State private var newAssignment: Assignment? = nil
    @State var newAssignmentViewIsPresented = false

    var body: some View {

        Group {
            if self.assignments.filter({ $0.course?.name == self.course?.name }).isEmpty {
                Text("No Assignments")
                    .foregroundColor(.secondary)
                    .font(.largeTitle)
            } else {
                List(assignments.filter { $0.course?.name == self.course?.name }, id: \.self) { assignment in
                    AssignmentRow(assignment: assignment).environment(\.managedObjectContext, self.context)
                }
            }
        }
        .navigationBarTitle(Text("\(course?.wrappedName ?? "")").foregroundColor(course?.color ?? Color.primary))
        .navigationBarItems(
            trailing: Button(
                action: {
                    self.newAssignment = Assignment(context: self.context)
                    self.newAssignmentViewIsPresented = true
            }
            ) {
                Image(systemName: "plus")
                    .accessibility(label: Text("New Assignment"))
                    .font(.title)

        })
            .accentColor(self.accentColor.color)
            .onAppear {
                self.accentColor.color = self.course?.color ?? .green
        }
        .sheet(isPresented: $newAssignmentViewIsPresented, content: {
            AssignmentEditorView(assignment: self.newAssignment!, defaultCourse: self.course).environment(\.managedObjectContext, self.context)
        })

    }
}
1 Answers

I was seeing an almost-identical crash. It seems there is still a bug with SwiftUI where @EnvironmentObject variables aren't accessible in child views.

Do you launch your CourseAssignmentsListView from a NavigationLink (in a NavigationView or List) or in a modal sheet? If so, try injecting your AccentColorManager directly in using the .environmentObject modifier - something like this:

// In the parent view
@EnvironmentObject var accentColor: AccentColorManager

// Wherever you are loading the view from... demonstrating using `NavigationLink`
NavigationLink(CourseAssignmentsListView().environmentObject(self.accentColor))

In my case, we have just had both people with crashes report that this approach works.

Related