PKDrawing.image crashes on iOS 17 (EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000210)

In 2 days we have observed in Crashlytics over 50 crashes related to PKDrawing.image with EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000210

So far all on iPads with A10, A12 and A13; 100% on iOS 17 (17.1.1, 17.2, 17.3) (while in others the percent of iOS 17 was around 60-80%).

Context: Images of the varying frame and scale resulting in screen resolution are being generated sequentially (in a background serial queue called almost one after another when requested), updating one CALayer.contents (and only after this update on Main Thread the next generation is allowed). One zoomable PKCanvasView is present on screen.

The crashing line in code:

let image = drawing.image(from: frame, scale: renderScale).cgImage

The questions:

  • Is there anything that can be done apart from throttling generation?
  • Can the circumstances of the crash be determined – are there any indications accessible in code before calling PKDrawing.image that app might crash?

The traces:

0
AGXMetalA12
AGX::BlitContext<AGX::G11::Encoders, AGX::G11::Classes, AGX::G11::ObjClasses>::copyTextureToBuffer(IOGPUMetalResource const*, unsigned long, unsigned long, unsigned long, AGXA12FamilyTexture*, unsigned int, unsigned int, MTLOrigin, MTLSize, unsigned long) + 96
9
PencilKit
PKDrawing.image(from:scale:) + 28
0
AGXMetalA13
<redacted> + 96
9
PencilKit
PKDrawing.image(from:scale:) + 28
0
AGXMetalA10
<redacted> + 72
9
PencilKit
$s9PencilKit9PKDrawingV5image4from5scaleSo7UIImageCSo6CGRectV_12CoreGraphics7CGFloatVtF + 24
Post not yet marked as solved Up vote post of IlyaY Down vote post of IlyaY
455 views

Replies

Got my hands on a 9th gen iPad and almost immediately caught a crash while debugging with an error in the line with PKDrawing.image (drawing with 4 strokes, renderScale = 8, size: 331x250) ,

-[MTLDebugRenderCommandEncoder setRenderPipelineState:]:1615: failed assertion Set Render Pipeline State Validation For color attachment 0, the renderPipelineState pixelFormat must be MTLPixelFormatInvalid, as no texture is set. the pipelineState's per sample imageBlock usage(10) is greater than the encoder's perSample imageBlock usage(6)