Hey all, been trying to setup an XR project with Babylon Native. The XR Session starts however at various points during the experience the following error gets thrown in XCode and freezes the app.
Error:
-[MTLDebugTexture setPurgeableState:]:832: failed assertion `Set Purgeable Stage Validation Cannot set purgeability state to volatile while resource is in use by a command buffer.'
The following error is thrown in the XCode console, referring to line 936 within xr/Source/ARKit/XR.mm
for the following lines:
[currentCommandBuffer addCompletedHandler:^(id<MTLCommandBuffer>) {
if (cameraTextureY != nil) {
[cameraTextureY setPurgeableState:MTLPurgeableStateEmpty];
}
if (cameraTextureCbCr != nil) {
[cameraTextureCbCr setPurgeableState:MTLPurgeableStateEmpty];
}
}];
Originally I was getting this error as soon as the WebXR session launched however we tried replacing it with the following code which reduces the frequency of the crash & allows us to run the XR session however it still occurs intermittently:
[currentCommandBuffer addCompletedHandler:^(id<MTLCommandBuffer>) {
id<MTLCommandBuffer> cleanupCommandBuffer = [commandQueue commandBuffer];
[cleanupCommandBuffer addCompletedHandler:^(id<MTLCommandBuffer>) {
if (cameraTextureY && cameraTextureY.allocatedSize > 0) {
NSLog(@"Setting cameraTextureY to purgeable.");
[cameraTextureY setPurgeableState:MTLPurgeableStateEmpty];
}
if (cameraTextureCbCr && cameraTextureCbCr.allocatedSize > 0) {
NSLog(@"Setting cameraTextureCbCr to purgeable.");
[cameraTextureCbCr setPurgeableState:MTLPurgeableStateEmpty];
}
}];
[cleanupCommandBuffer commit];
}];
This occurs while within an XR Session and can occur for a variety of reasons such as loading a large 3D model while in session.
It seems to occur at random, however the pattern is this occurs whenever there is a significant frame drop. Once this error occurs the XR session freezes.
Platform: iOS 17.6
===
I’ve created a GitHub Issue as well - (XR Session Crashes Frequently · Issue #1456 · BabylonJS/BabylonNative · GitHub)
==
Would love any help on how to proceed, thank you!