ECS Physics Bug "No free leaf slot found in leaf node"

Hey Guys!
I am having around 25k entities with colliders attached in my scene. From time to time (every 2nd or 3rd run) I am getting the following error in editor (endlessly repeating):

System.InvalidOperationException: No free leaf slot found in leaf node.
at Unity.Physics.SafetyChecks.ThrowInvalidOperationException (Unity.Collections.FixedString128Bytes message) [0x00000] in .\Library\PackageCache\com.unity.physics\Unity.Physics\Extensions\SafetyChecks.cs:359
at Unity.Physics.BoundingVolumeHierarchy.Insert (Unity.Physics.Aabb aabb, Unity.Physics.BoundingVolumeHierarchy+PointAndIndex point, Unity.Physics.CollisionFilter filter) [0x0030d] in .\Library\PackageCache\com.unity.physics\Unity.Physics\Collision\Geometry\BoundingVolumeHierarchy.cs:847
at Unity.Physics.BoundingVolumeHierarchy+IncrementalInsertionContext.Insert (Unity.Physics.BoundingVolumeHierarchy& bvh, Unity.Physics.Aabb aabb, Unity.Physics.BoundingVolumeHierarchy+PointAndIndex point, Unity.Physics.CollisionFilter filter) [0x00001] in .\Library\PackageCache\com.unity.physics\Unity.Physics\Collision\Geometry\BoundingVolumeHierarchy.cs:377
at Unity.Physics.Broadphase+Tree.BuildIncremental () [0x00198] in .\Library\PackageCache\com.unity.physics\Unity.Physics\Collision\World\Broadphase.cs:706
at Unity.Physics.Broadphase+BuildIncrementalTreeJob.Execute () [0x00001] in .\Library\PackageCache\com.unity.physics\Unity.Physics\Collision\World\Broadphase.cs:963
at Unity.Jobs.IJobExtensions+JobStruct1[T].Execute (T& data, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) [0x00001] in <44f3679c53d1477a9c6e72f269e3a3a9>:0 at (wrapper delegate-invoke) Unity.Jobs.IJobExtensions+JobStruct1+ExecuteJobFunction[Unity.Physics.Broadphase+BuildIncrementalTreeJob].invoke_void_T&_intptr_intptr_JobRanges&_int(Unity.Physics.Broadphase/BuildIncrementalTreeJob&,intptr,intptr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,int)

Interestingly this is not necessarily related to the huge amount of entities. when loading 70k+ entities it works better and the issue doesn’t appear. Not sure if this issue is related to ECS physics or Unity physics as I use both in the scene.

Has anybody a clue what’s going on here?
Thanks!

PS.: Using Unity 6000.0.32f1, latest ECS physics

Update: After digging further into that I realized that this script could be the cause of this issue:


The bug was related to the number of entities (using more did not result in this issue). As soon as disabling this script the exception was gone.

The issue was likely due to the fact that you were using the incremental broadphase (both ticked here) which seems to run into issues in your scene.
You could add the script back and disable these options and the issue should go away.