BabylonJS / BabylonJS/BabylonNative
XR Session Crashes Frequently
- Dominant language
- C++
- Stars
- 919
- Forks
- 162
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 19
Description
**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) {
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) {
id cleanupCommandBuffer = [commandQueue commandBuffer];
[cleanupCommandBuffer addCompletedHandler:^(id) {
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
Contributor guide
Assessment
This issue has not been assessed yet.