SwiftUI App Crashes only on Real iOS Device.

I have some weird SwiftUI error on Xcode Version 14.1 (14B47b) with iPhone XR (16.0.2).

The same code is running well on the simulator just having crashes on real devices.

Thread 1: EXC_BAD_ACCESS (code=2, address=0x16adf7f68) KERN_PROTECTION_FAILURE

var paymentTimelineButton: some View {
ZStack(alignment: .trailing) {
      HStack {
        Image("ic_bag")
          .renderingMode(.template)
          .resizable()
          .aspectRatio(contentMode: .fit)
          .frame(width: 22, height: 22)
          .foregroundColor(.white)
        Text("Payment Timeline per Property")
          .font(Font.SF.semibold15)
          .foregroundColor(.white)
        Button(action: {
          toastMessage = "Timeline allows you to track your payments.".localized
          toastType = -1
        }) {
          Image("ic_question")
            .resizable()
            .aspectRatio(contentMode: .fit)
            .frame(width: 18, height: 18)
        }
      }
      .frame(width: 214, height: 46)
      .background((cItem.hasPaymentTimeline || cItem.isOwner || cUserType == .customer) ? K.Colors.c3775CE : K.Colors.c678B8D)
      .cornerRadius(22, corners: [.topLeft, .bottomLeft])
      .cornerRadius(10, corners: [.topRight, .bottomRight])
      .padding(.trailing)
      .offset(x: 0, y: -24)
      .onTapGesture {
        if (caseItem.hasPaymentTimeline) {
          checkCDAvailable()
        }
        else {
          toastMessage = "Please contact the owner for accessing payment timeline. Make sure the case owner has answered the questions.".localized
          toastType = -1
        }
      }
       
      BadgeView(size: 6)
        .offset(x: -13, y: -46)
    } //ZStack
.padding(.bottom, -24)
  } //paymentTimelineButton

So what would cause an error like this?

Thanks in advance for your time

Parth

Where exactly in code does the crash occur ?

@Claide31 Crash does not occur if I comment out any these two blocks

// 1
.background((cItem.hasPaymentTimeline || cItem.isOwner || cUserType == .customer) ? K.Colors.c3775CE : K.Colors.c678B8D)
// 2
BadgeView(size: 6)
        .offset(x: -13, y: -46)

Actually if you try to use this code in a separate view there is not any issue, And that's why I can not identify the exact root cause of this crash.

SwiftUI App Crashes only on Real iOS Device.
 
 
Q