PencilKit is throwing GPU/Metal errors (Insufficient Memory)

For context: I'm working on a score pad app, with the ability to have a column of PKCanvases, so you can just hand write things without them being scribbled into text. As part of my stress testing, I basically filled the grid with ~50 canvases, and it seems that after a certain amount of CanvasViews are added to the score pad, my M1 iPad Pro GPU is unable to keep up.

Occasionally, a cell will just entirely render as magenta, and I will have dozens and dozens of Execution of the command buffer was aborted due to an error during execution. Insufficient Memory (IOAF code 8) logs thrown to the console.

I honestly don't know where to go from here. I recognize that what I'm doing is almost definitely not what PencilKit was designed for, but I also know the API is relatively young. I can't tell if this is a bug that should be fixed by Apple, or entirely my fault and a sign that I need to redo the entire thing.

I've attached a screenshot with the magenta cell, there's also another two cells where the pencil strokes are just thick black squares. I'd appreciate any advice or help, I can't even seem to find any way to detect and recover from this in my code, as trying to search for Metal errors gives me discussions about writing Metal apps, which this isn't. It's a pure SwiftUI app with some PencilKit canvases.

Hi pgelvinaz!

Do you observe that on iPadOS15 beta? Do you think you can share an application binary and file a feedback assistant ticket so we could have a look?

Eugene.

Some additional information: I'm not on the beta, my iPad is running 14.6. Also, Insufficient memory is the most common error I see, but other times it'll be a [CAMetalLayer setInputTime:] - non-zero time already exists!. Either way, they happen dozens of times every pencil stroke once it's reached its limits. The total ram usage of the app is anywhere between 150-500 MB when this happens. Looking for memory leaks, it seems that Instruments identifies instantiating a PKCanvasView as the source of a leak.

[Moved comment to an answer below]

Is there any update on this? I'm experiencing a very similar problem with a grid of PKCanvasViews only since iPadOS 15. My canvases' presentations stay blank although the touchesBegan/Moved/Ended/Cancelled events are registered. The strokes are just not visible. No unexpected background coloration or faulty black rectangular presentation of strokes here. (I set the canvases' background color to clear.)

  • Any first and second grid PKCanvasView I draw in will behave normally.
  • Any third grid PKCanvasView I draw in will show the stroke while drawing. When finished, the stroke will disappear and several insufficient memory errors are thrown.
  • Any fourth or later grid PKCanvasView I draw in will show neither currently drawn nor finished strokes. Throughout the drawing, insufficient memory errors and occasional non-zero time already exists errors are thrown.

Please any solutions here? It seems that each PKCanvasView created allocates somewhere between 1-5 mb of space, so if you create 30 on a page (which, seems reasonable to me as someone who is providing a calendar view with a difference view per cell) the device runs out of memory... even though the memory isn't being used?

I'm also getting the insufficient memory errors and my canvases are not even visible all at the same time. I think in my case it has something to do with an environmentObject variable that holds a list of pkdrawings for each canvas. If i change that environmentObject variable to a state variable things are better, but then i lose drawings as others are added to the object. Not sure how to overcome this....

Execution of the command buffer was aborted due to an error during execution. Insufficient Memory (00000008:kIOGPUCommandBufferCallbackErrorOutOfMemory)

PencilKit is throwing GPU/Metal errors (Insufficient Memory)
 
 
Q