CALayerInvalidGeometry crash in SwiftUI

I have had a suspicious crash in my app for a long time. I'm 95% using SwiftUI and have to use only one UIKit view that I embed into SwiftUI in my app. I don't understand why my app crashes when the CALayer position is set to Nan because I don't reference layers at all, including that UIKit view. Any ideas why it may happen and how can I reproduce it?

Fatal Exception: CALayerInvalidGeometry CALayer position contains NaN: [nan nan]. Layer: <CAShapeLayer:0x303cd9600; position = CGPoint (0 0); bounds = CGRect (0 0; 0 0); delegate = _NoAnimationDelegate; allowsGroupOpacity = YES; anchorPoint = CGPoint (0 0); >

Fatal Exception: CALayerInvalidGeometry
0  CoreFoundation                 0x83f20 __exceptionPreprocess
1  libobjc.A.dylib                0x16018 objc_exception_throw
2  CoreFoundation                 0x1826dc -[NSException initWithCoder:]
3  QuartzCore                     0x7b28 CA::Layer::set_position(CA::Vec2<double> const&, bool)
4  QuartzCore                     0x7a58 -[CALayer setPosition:]
5  SwiftUI                        0x1a131d4 objectdestroy.10Tm
6  SwiftUI                        0x1a12ab4 objectdestroy.10Tm
7  SwiftUI                        0x281590 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
8  SwiftUI                        0x280c0c -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
9  SwiftUI                        0x28083c -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
10 SwiftUI                        0x27eaf8 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
11 SwiftUI                        0x27e2c0 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
12 SwiftUI                        0x27c6b0 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
13 SwiftUI                        0x27bba8 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
14 SwiftUI                        0x27c480 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
15 SwiftUI                        0x27bba8 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
16 SwiftUI                        0x27c480 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
17 SwiftUI                        0x27bba8 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
18 SwiftUI                        0x27c480 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
19 SwiftUI                        0x27bba8 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
20 SwiftUI                        0x27e408 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
21 SwiftUI                        0x27c6b0 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
22 SwiftUI                        0x27bba8 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
23 SwiftUI                        0x27c480 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
24 SwiftUI                        0x27bba8 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
25 SwiftUI                        0x1a34a8 get_witness_table 7SwiftUI4ViewRzAA7GestureRd__r__lAA15ModifiedContentVyxAA03AddD8ModifierVyqd__GGAaBHPxAaBHD1__AhA0cH0HPyHCHCTm
26 SwiftUI                        0x1a323c get_witness_table 7SwiftUI4ViewRzAA7GestureRd__r__lAA15ModifiedContentVyxAA03AddD8ModifierVyqd__GGAaBHPxAaBHD1__AhA0cH0HPyHCHCTm
27 SwiftUI                        0x1a2c54 get_witness_table 7SwiftUI4ViewRzAA7GestureRd__r__lAA15ModifiedContentVyxAA03AddD8ModifierVyqd__GGAaBHPxAaBHD1__AhA0cH0HPyHCHCTm
28 SwiftUI                        0x1a2ba4 get_witness_table 7SwiftUI4ViewRzAA7GestureRd__r__lAA15ModifiedContentVyxAA03AddD8ModifierVyqd__GGAaBHPxAaBHD1__AhA0cH0HPyHCHCTm
29 SwiftUI                        0x1a2ab0 get_witness_table 7SwiftUI4ViewRzAA7GestureRd__r__lAA15ModifiedContentVyxAA03AddD8ModifierVyqd__GGAaBHPxAaBHD1__AhA0cH0HPyHCHCTm
30 SwiftUI                        0x1a2a78 get_witness_table 7SwiftUI4ViewRzAA7GestureRd__r__lAA15ModifiedContentVyxAA03AddD8ModifierVyqd__GGAaBHPxAaBHD1__AhA0cH0HPyHCHCTm
31 SwiftUI                        0x1a2a40 get_witness_table 7SwiftUI4ViewRzAA7GestureRd__r__lAA15ModifiedContentVyxAA03AddD8ModifierVyqd__GGAaBHPxAaBHD1__AhA0cH0HPyHCHCTm
32 SwiftUI                        0x1a2930 get_witness_table 7SwiftUI4ViewRzAA7GestureRd__r__lAA15ModifiedContentVyxAA03AddD8ModifierVyqd__GGAaBHPxAaBHD1__AhA0cH0HPyHCHCTm
33 UIKitCore                      0x95540 +[UIView(Animation) performWithoutAnimation:]
34 SwiftUI                        0x2686ec -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
35 SwiftUI                        0x2656d8 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
36 SwiftUI                        0x263d7c -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
37 SwiftUI                        0x18eedc OUTLINED_FUNCTION_519
38 SwiftUI                        0x18e8d8 OUTLINED_FUNCTION_519
39 SwiftUI                        0x18e768 OUTLINED_FUNCTION_519
40 QuartzCore                     0xd0ecc CA::Display::DisplayLinkItem::dispatch_(CA::SignPost::Interval<(CA::SignPost::CAEventCode)835322056>&)
41 QuartzCore                     0xcf230 CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long)
42 QuartzCore                     0xcedd0 CA::Display::DisplayLink::dispatch_deferred_display_links(unsigned int)
43 UIKitCore                      0xb776c _UIUpdateSequenceRun
44 UIKitCore                      0xb73b0 schedulerStepScheduledMainSection
45 UIKitCore                      0xb8254 runloopSourceCallback
46 CoreFoundation                 0x56834 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
47 CoreFoundation                 0x567c8 __CFRunLoopDoSource0
48 CoreFoundation                 0x54298 __CFRunLoopDoSources0
49 CoreFoundation                 0x53484 __CFRunLoopRun
50 CoreFoundation                 0x52cd8 CFRunLoopRunSpecific
51 GraphicsServices               0x11a8 GSEventRunModal
52 UIKitCore                      0x40a90c -[UIApplication _run]
53 UIKitCore                      0x4be9d0 UIApplicationMain
54 SwiftUI                        0x3f4148 OUTLINED_FUNCTION_283
55 SwiftUI                        0x3a0714 OUTLINED_FUNCTION_283
56 SwiftUI                        0x3ac4d0 OUTLINED_FUNCTION_283
57 VerkadaPass                    0xd1b4 main (MyApp.swift)
58 ???                            0x1ca1dde4c (Missing)

We have the same crash that spikes sometimes to thousands of crashes and than disappears magically! We do use a webview inside a swiftUI where we load some HTML with Javascript. The size of that is determined by the moder KVO way:

webView.scrollView.publisher(for: \.contentSize)
    .removeDuplicates()
    .sink { [weak self] contentSize in self?.contentSize = contentSize }
    .store(in: &cancellable)

I'm not sure if this causes the problem with a specific HTML payload! @ivavilov are you using similar code?

CALayerInvalidGeometry crash in SwiftUI
 
 
Q