SwiftUI crash in AlertBridge.preferencesDidChange(_:)

i am seeing a number of SwiftUI crashes that only occur on iOS 13 with a stack trace that ends with a call to AlertBridge.preferencesDidChange(_:).

Does anyone have any insight into what might be causing this?

Code Block language
Crashed: com.apple.main-thread
0 SwiftUI 0x1f6860ae8 AlertBridge.preferencesDidChange(_:) + 2604
1 SwiftUI 0x1f6458474 _UIHostingView.preferencesDidChange() + 412
2 SwiftUI 0x1f65262cc ViewGraph.updateOutputs(at:) + 180
3 SwiftUI 0x1f67c5e10 closure #1 in closure #1 in ViewRendererHost.render(interval:updateDisplayList:) + 816
4 SwiftUI 0x1f67c52b0 closure #1 in ViewRendererHost.render(interval:updateDisplayList:) + 524
5 SwiftUI 0x1f67bc1b8 ViewRendererHost.render(interval:updateDisplayList:) + 316
6 SwiftUI 0x1f68e2748 _UIHostingView.layoutSubviews() + 160
7 SwiftUI 0x1f68e2774 @objc _UIHostingView.layoutSubviews() + 24



Could you show the code, not only the crash report ?
Is AlertBridge a class of yours ?

If that can help, similar problem here:
https://developer.apple.com/forums/thread/662575
AlertBridge is not a class of mine. Strangely, the stack trace reported by Crashlytics does not have any of my code. Here is the complete stack trace. Again, none of the classes seen in the stack trace are mine.

Code Block language
0 SwiftUI 0x1c9bf3ae8 AlertBridge.preferencesDidChange(_:) + 2604
1 SwiftUI 0x1c97eb474 _UIHostingView.preferencesDidChange() + 412
2 SwiftUI 0x1c98b92cc ViewGraph.updateOutputs(at:) + 180
3 SwiftUI 0x1c9b58e10 closure #1 in closure #1 in ViewRendererHost.render(interval:updateDisplayList:) + 816
4 SwiftUI 0x1c9b582b0 closure #1 in ViewRendererHost.render(interval:updateDisplayList:) + 524
5 SwiftUI 0x1c9b4f1b8 ViewRendererHost.render(interval:updateDisplayList:) + 316
6 SwiftUI 0x1c9c75748 _UIHostingView.layoutSubviews() + 160
7 SwiftUI 0x1c9c75774 @objc _UIHostingView.layoutSubviews() + 24
8 UIKitCore 0x195f657fc -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2144
9 QuartzCore 0x198509494 -[CALayer layoutSublayers] + 284
10 QuartzCore 0x19850f5ec CA::Layer::layout_if_needed(CA::Transaction*) + 468
11 QuartzCore 0x19851a128 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 140
12 QuartzCore 0x198462b44 CA::Context::commit_transaction(CA::Transaction*, double) + 296
13 QuartzCore 0x19848c4e4 CA::Transaction::commit() + 676
14 UIKitCore 0x195ada9d0 _afterCACommitHandler + 140
15 CoreFoundation 0x19197af2c CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 32
16 CoreFoundation 0x191975e20 CFRunLoopDoObservers + 420
17 CoreFoundation 0x19197629c CFRunLoopRun + 968
18 CoreFoundation 0x191975ba8 CFRunLoopRunSpecific + 424
19 GraphicsServices 0x19baec344 GSEventRunModal + 160
20 UIKitCore 0x195ab13e4 UIApplicationMain + 1932
21 Kevo 0x1029d1418 main + 17 (main.m:17)
22 libdyld.dylib 0x1917fd8f0 start + 4


This crash happens when updating an alert item while the alert is shown. This bug is fixed in iOS 14. The following is a sample code to simulate the crash (Note that you shouldn't dismiss the first alert):

struct MessageInfo: Identifiable {
  let title: String
  let message: String
   
  var id: String {
    "\(title)-\(message)"
  }
}

struct ContentView: View {
  @State private var messageInfo: MessageInfo?

  var body: some View {
    Text("Test Alert Updating")
      .font(.largeTitle)
      .alert(item: $messageInfo) { info in
        let titleText = Text(info.title)
        let messageText = Text(info.message)
        let dismissButton = Alert.Button.default(Text("OK"))

        return Alert(title: titleText,
               message: messageText,
               dismissButton: dismissButton)
      }
      .onAppear {
        DispatchQueue.global(qos: .userInitiated).asyncAfter(deadline: .now().advanced(by: .seconds(1))) {
          messageInfo = .init(title: "Alert 1", message: "Test Alert 1")
        }
         
        DispatchQueue.global(qos: .userInitiated).asyncAfter(deadline: .now().advanced(by: .seconds(2))) {
          messageInfo = .init(title: "Alert 2", message: "Test Alert 2")
        }
      }
  }
}
SwiftUI crash in AlertBridge.preferencesDidChange(_:)
 
 
Q