iOS 16 Crash - [UIView bounds] + 32

I am seeing crashes in my iOS Swift project. We are targeting iOS >= 13 and are seeing a crash that is only happening on iOS 16. Prior to iOS 16 we were not seeing the crash.

Myself and team have yet to be able to reproduce.

From our analytics tracking and logging, it looks as if the crash is happening when the user navigates to one of our view controllers containing a WKWebView or shortly there after. The view controllers are composed of a table view rendering a cell with a WKWebView. The other cells in the table views are reused else where within the application and are working just fine. It seems to be directly related to the cell containing the WKWebView.

Any ideas on what the problem could be?

Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x1c20 objc_msgSend + 32
1  UIKitCore                      0x59d4 -[UIView bounds] + 32
2  UIKitCore                      0x144260 -[UIScrollView _didEndDirectManipulationWithScrubbingDirection:] + 112
3  UIKitCore                      0x143d84 -[UIScrollView _stopScrollingNotify:pin:tramplingDragFlags:] + 116
4  UIKitCore                      0x2c9718 -[UIScrollView _stopScrollingAndZoomingAnimationsPinningToContentViewport:tramplingDragFlags:] + 52
5  UIKitCore                      0x2c93f8 -[UIScrollView dealloc] + 88
6  libobjc.A.dylib                0x15d8 AutoreleasePoolPage::releaseUntil(objc_object**) + 196
7  libobjc.A.dylib                0x4f80 objc_autoreleasePoolPop + 256
8  CoreFoundation                 0x7e764 _CFAutoreleasePoolPop + 32
9  CoreFoundation                 0x7c4b8 __CFRunLoopPerCalloutARPEnd + 48
10 CoreFoundation                 0x1a2f8 __CFRunLoopDoObservers + 572
11 CoreFoundation                 0x7bc7c __CFRunLoopRun + 1048
12 CoreFoundation                 0x80ed4 CFRunLoopRunSpecific + 612
13 GraphicsServices               0x1368 GSEventRunModal + 164
14 UIKitCore                      0x3a23d0 -[UIApplication _run] + 888
15 UIKitCore                      0x3a2034 UIApplicationMain + 340
16 <App>                          0x450c main + 4310877452 (<compiler-generated>:4310877452)
17 ???                            0x1f4b10960 (Missing)```

Replies

Crashing early in objc_msgSend is usually an indication that you have a bad object of some kind. If I'm reading the assembly correctly, it looks like the isa (basically the class pointer) of the object has likely been smashed. The offset in -[UIView bounds] is where we call into -[CALayer bounds] which would indicate the smashed object is likely a view's layer, although I don't have a good sense for which one it would be in this case.

Do you have any suggestion on how we could narrow down which view is getting smashed? @Rincewind

I have a height constraint that I am manipulating for the WKWebView height inside the cell.

When the WKWebView finishes loading the js with webView.evaluateJavaScript("document.readyState") we are calling webView.evaluateJavaScript("document.documentElement.scrollHeight") to get the height. Then we update the height constraint constant.

Since this issue seems to be only happening in our table view controllers with the WKWebView it is making me think the web view is the object getting smashed. The other cells in the table view are dynamically sizing themselves via AutoLayout and are being reused across the app with no issues that I can see.

I think my bet would be on a subview of the WKWebView being deallocated (and happening to be a UIScrollView). You might try setting a breakpoint in -[UIScrollView dealloc] to see if something unexpected is happening.