VisionOS : RealityKit/RealityView crashes with many physics entities, in immersive mode

I've been getting random crashes in an immersive RealityView, using model entities with physics. While the crashes do randomly happen with fewer objects, they can be reproduced consistently by placing 100 objects on top of each other.

The project I used as a starter, is here : https://developer.apple.com/documentation/visionos/incorporating-real-world-surroundings-in-an-immersive-experience

To reproduce the error, create 100 cubes in a loop on top of each other in addCube, instead of creating just 1. This gives exc_bad_access, as soon as the cubes are created. Tested on a Vision Pro, not a simulator.

Any advice on how to resolve this? I'm trying to have around 100 objects moving around the environment, but it still gives exc_bad_access, eventually.

I'm trying to attach the crash log, but I keep getting the error about sensitive materials. Testing to see if I can post without it.

I had similar problem when I try to load many objects asnyc at same time. Finally I had an ugly idea that create a loading queue, which not to load the objects at once but one by one which solved the problem. It may take a little longer time but works for me. Hope for any better solution.

I have a similar RealityView crash that originally I was attributing to the # of objects but now I am wondering if this is an issue of programmatically loading / adding a bunch of entities asynchronously. I will have to try what you have done and see if it works better.

VisionOS : RealityKit/RealityView crashes with many physics entities, in immersive mode
 
 
Q