Metric Crash by Widget SwiftUI

I have the following code. This part of the code is used in the widget

var body: some View {
        VStack(){
            Image(uiImage: imageFromUrl(item.icon) ?? defaultImage!)//(onlineImage ?? defaultImage)!
                .resizable()
                .frame(width: itemH * 0.70, height: itemH * 0.70)
                .aspectRatio(contentMode: .fit)
            Text(item.name)
                .font(.system(size: titleFont))
                .foregroundColor(colorGenerate(0x333333))
                .background(Color.clear)
                .frame(width: imageWH, height: itemH*0.2)
                .lineLimit(1)
                .onAppear {
                }
        }
        .frame(width: imageWH, height: itemH)
        .background(Color.clear)
    }

I really can't find what caused the crash.Or maybe the system killed it directly, but why should it be reported through metrics? The collection of this question is entirely from metrickit

There is no problem at the code level, but the following crash occurs on the actual user's phone:

Date/Time:       2024-08-08 00:59:09.000 +0800

OS Version:      iOS iPhone OS 17.5.1 (21F90) (iPhone OS 17.5.1 (21F90))

Report Version:  104



Exception Type:  EXC_BREAKPOINT (SIGTRAP)

Exception Codes: EXC_BREAKPOINT at 0x0000000000000000

Crashed Thread:  0



Application Specific Information:

*** Terminating app due to uncaught exception '(null)', reason: ''


Thread 0:

0   widgetExtension                 0x000000010023ee54 0x15ae54 + closure #1 () -> SwiftUI.TupleView<(<<opaque return type of (extension in SwiftUI):SwiftUI.View.aspectRatio(_: Swift.Optional<CoreGraphics.CGFloat>, contentMode: SwiftUI.ContentMode) -> some>>.0, <<opaque return type of (extension in SwiftUI):SwiftUI.View.onAppear(perform: Swift.Optional<() -> ()>) -> some>>.0)> in widgetExtension.xxView.body.getter : some + 1408

1   widgetExtension                 0x000000010023e6d8 0x15a6d8 + body.get(<compiler-generated>:36)

2   widgetExtension                 0x000000010023eeac 0x15aeac + body.get(<compiler-generated>:0)

3   SwiftUI                         0x00000001955b6528 0x202528 + _dynamic_cast_existential_0_superclass_conditional + 24428

4   SwiftUI                         0x00000001955b2f2c 0x1fef2c + _dynamic_cast_existential_0_superclass_conditional + 10608

5   SwiftUI                         0x00000001955b2a4c 0x1fea4c + _dynamic_cast_existential_0_superclass_conditional + 9360

6   SwiftUI                         0x00000001955b1b30 0x1fdb30 + _dynamic_cast_existential_0_superclass_conditional + 5492

7   AttributeGraph                  0x00000001ba209010 0x9010 + AG::Graph::UpdateStack::update() + 512

8   AttributeGraph                  0x00000001ba208bfc 0x8bfc + AG::Graph::update_attribute(AG::data::ptr<AG::Node>, unsigned int) + 424

9   AttributeGraph                  0x00000001ba202cc0 0x2cc0 + AG::Graph::input_value_ref_slow(AG::data::ptr<AG::Node>, AG::AttributeID, unsigned int, unsigned int, AGSwiftMetadata const*, unsigned char&, long) + 720

10  AttributeGraph                  0x00000001ba202854 0x2854 + _AGGraphGetValue + 228

11  SwiftUI                         0x000000019552cdac 0x178dac + _OUTLINED_FUNCTION_1130 + 23736

12  SwiftUI                         0x000000019552cd3c 0x178d3c + _OUTLINED_FUNCTION_1130 + 23624

13  AttributeGraph                  0x00000001ba209010 0x9010 + AG::Graph::UpdateStack::update() + 512

14  AttributeGraph                  0x00000001ba208bfc 0x8bfc + AG::Graph::update_attribute(AG::data::ptr<AG::Node>, unsigned int) + 424

15  AttributeGraph                  0x00000001ba202ae0 0x2ae0 + AG::Graph::input_value_ref_slow(AG::data::ptr<AG::Node>, AG::AttributeID, unsigned int, unsigned int, AGSwiftMetadata const*, unsigned char&, long) + 240

16  AttributeGraph                  0x00000001ba207c34 0x7c34 + _AGGraphGetInputValue + 248

17  SwiftUI                         0x00000001955fc458 0x248458 + -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled] + 10764

18  SwiftUI                         0x0000000195607dc8 0x253dc8 + -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled] + 58236

19  SwiftUI                         0x0000000195607d54 0x253d54 + -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled] + 58120

20  SwiftUI                         0x00000001956d9318 0x325318 + -[NSAttributedString(SPI) initSwiftUIAttributedStringWithFormat:options:locale:arguments:] + 10028

21  SwiftUI                         0x000000019561ec30 0x26ac30 + -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled] + 152036

22  SwiftUI                         0x0000000195606ad8 0x252ad8 + -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled] + 53388

23  SwiftUI                         0x00000001956066bc 0x2526bc + -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled] + 52336

24  SwiftUI                         0x0000000195550f34 0x19cf34 + _get_witness_table 7SwiftUI4ViewRzAA7GestureRd__r__lAA15ModifiedContentVyxAA03AddD8ModifierVyqd__GGAaBHPxAaBHD1__AhA0cH0HPyHCHCTm + 14012

25  SwiftUI                         0x0000000195550d14 0x19cd14 + _get_witness_table 7SwiftUI4ViewRzAA7GestureRd__r__lAA15ModifiedContentVyxAA03AddD8ModifierVyqd__GGAaBHPxAaBHD1__AhA0cH0HPyHCHCTm + 13468

26  SwiftUI                         0x000000019555016c 0x19c16c + _get_witness_table 7SwiftUI4ViewRzAA7GestureRd__r__lAA15ModifiedContentVyxAA03AddD8ModifierVyqd__GGAaBHPxAaBHD1__AhA0cH0HPyHCHCTm + 10484

27  SwiftUI                         0x0000000195539518 0x185518 + _OUTLINED_FUNCTION_519 + 3752

28  SwiftUI                         0x0000000195539324 0x185324 + _OUTLINED_FUNCTION_519 + 3252

29  AttributeGraph                  0x00000001ba209010 0x9010 + AG::Graph::UpdateStack::update() + 512

30  AttributeGraph                  0x00000001ba208bfc 0x8bfc + AG::Graph::update_attribute(AG::data::ptr<AG::Node>, unsigned int) + 424

31  AttributeGraph                  0x00000001ba202cc0 0x2cc0 + AG::Graph::input_value_ref_slow(AG::data::ptr<AG::Node>, AG::AttributeID, unsigned int, unsigned int, AGSwiftMetadata const*, unsigned char&, long) + 720

32  AttributeGraph                  0x00000001ba207c34 0x7c34 + _AGGraphGetInputValue + 248

33  SwiftUI                         0x000000019560665c 0x25265c + -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled] + 52240

34  SwiftUI                         0x0000000195550914 0x19c914 + _get_witness_table 7SwiftUI4ViewRzAA7GestureRd__r__lAA15ModifiedContentVyxAA03AddD8ModifierVyqd__GGAaBHPxAaBHD1__AhA0cH0HPyHCHCTm + 12444

35  SwiftUI                         0x0000000195550d5c 0x19cd5c + _get_witness_table 7SwiftUI4ViewRzAA7GestureRd__r__lAA15ModifiedContentVyxAA03AddD8ModifierVyqd__GGAaBHPxAaBHD1__AhA0cH0HPyHCHCTm + 13540

...

Have you removed items one at a time to see if the crash happens? In other words, remove the Image and see if it crashes. If not, it's the Image causing the issue. If not, remove the Text, etc.

If it still crashes, then remove all attributes and add them back one at a time until it crashes.

As an aside, your code can be cleaned up a little:

  1. I doubt you need the clear backgrounds.
  2. foregroundColor() is deprecated. You should use foregroundStyle() instead.
  3. .onAppear {} doesn't seem to have anything in it, so remove it. (You may have removed the contents for this post.)
  4. VStack(){ doesn't need empty parentheses, so can be VStack {.

Does defaultImage exist as a UIImage?

Are your frame sizes valid? That might trigger metrics issues.

Metric Crash by Widget SwiftUI
 
 
Q