[CAMetalLayer nextDrawable] returning nil because allocation failed.

Why do I get this error almost immediately on starting my rendering pass?

Multiline BlockQuote. 2024-05-29 20:02:22.744035-0500 RoomPlanExampleApp[491:10341] [] <<<< AVPointCloudData >>>> Fig assert: "_dataBuffer" at bail (AVPointCloudData.m:217) - (err=0)

2024-05-29 20:02:22.744455-0500 RoomPlanExampleApp[491:10341] [] <<<< AVPointCloudData >>>> Fig assert: "_dataBuffer" at bail (AVPointCloudData.m:217) - (err=0) 2024-05-29 20:05:54.079981-0500 RoomPlanExampleApp[491:10025] [CAMetalLayer nextDrawable] returning nil because allocation failed. 2024-05-29 20:05:54.080144-0500 RoomPlanExampleApp[491:10341] [] <<<< AVPointCloudData >>>> Fig assert: "_dataBuffer" at bail (AVPointCloudData.m:217) - (err=0)

Answered by DTS Engineer in 789248022

Hello,

When you call nextDrawable it behaves as follows:

"A CAMetalLayer object maintains an internal pool of textures for displaying layer content, each wrapped in a CAMetalDrawable object. Use this method to retrieve the next available drawable from the pool. If all drawables are in use, the layer waits up to one second for one to become available, after which it returns nil."

In this case it seems as though CAMetalLayer fails to allocate a drawable (and returns nil) because all other drawables are in use by your app in other rendering passes.

Try doing less work in a pass or optimize it to help ensure there is a drawable available. A speedier SoC can also process your workload faster.

We get the same in our app, using ARKit (ARSCNView). Just a ton of these

<<<< AVPointCloudData >>>> Fig assert: "_dataBuffer" at bail (AVPointCloudData.m:217) - (err=0)

while the ARSession hangs for some time (up to 20s). And then it works normally.

Accepted Answer

Hello,

When you call nextDrawable it behaves as follows:

"A CAMetalLayer object maintains an internal pool of textures for displaying layer content, each wrapped in a CAMetalDrawable object. Use this method to retrieve the next available drawable from the pool. If all drawables are in use, the layer waits up to one second for one to become available, after which it returns nil."

In this case it seems as though CAMetalLayer fails to allocate a drawable (and returns nil) because all other drawables are in use by your app in other rendering passes.

Try doing less work in a pass or optimize it to help ensure there is a drawable available. A speedier SoC can also process your workload faster.

Not the best solution but I will try it out

I tried cutting it back by commenting out all of my debug prints that I had. I still had errors. I moved up to IOS18 as recommended by an Apple support person to see if I could get more memory allocated. Then I ran afoul of the dreaded sandbox requirement that is being enforced. I am also getting errors from the IMU that say the data flow was less than normal and the tone of the message indicates it could be a hardware or delegate issue. Through what delegate is IMU data delivered?

MarnixArnold, When this happens do you get a "SessionInterrupted" event reported? What is the reason for the interruption when you get the "Ended" event? I am seeing a possible linkage between the two

DTS Engineer, how do. you "do less work" when the default minimum is already being done. I had a number of debugging displays of data structures in motion. Turning off the displays was not effective in reducing the work enough. My suspicion is that the. delegate queue is being delayed by the activities of other delegates for class processing.

[CAMetalLayer nextDrawable] returning nil because allocation failed.
 
 
Q