Hey! First of all thanks for the great work on this very impressive physics engine. I'm working on a game where I originally had my own collision detection and physics but as I wanted more and more complex stuff I decided it's better to get yours which already
had everything I needed. It was some work to change the entire game to the new system, but I've got most everything working now.
A problem I've run into is that when I remove objects from the simulator the arbiter count goes up about 10-15 for every object removed, and they stay there indefinitely, which means that if I remove say 100 items I'll have about invalid 1000-1500 arbiters.
I've tried looking through my own code as I assume the problem is my own fault, but I can't seem to find any errors.
I'm using SAT for narrow and SS for broad and the error only seems to exist when using SelectiveSweep for narrow. The broad phase doesn't make any difference but when running S&P or Bruteforce the extra arbiters aren't created.
The item removal happens when my player object collides with the target item, if that makes any difference.
This happens when using both Simulator.Remove() and Geom.Dispose() / Body.Dispose()
My game object currently is the container for a Body and a Geom. My code for removing my gameobject from my world is:
The removal gets called all the way into the SelectiveSweep.ProcessRemovedGeoms() and it does remove objects from it's _wrapper list. However the arbiter list still increases.
public virtual void Dispose()
if (IsDisposed) return;
IsDisposed = true;
One idea is that the problem lies in removing arbiters associated with the removed geoms, since the check for this (in PhysicsSimulator.ProcessRemovedItems()) never returns true. However it never returns true when using other narrow colliders either so that
might not be the source of the problem either.
I apologize beforehand as I'm assuming that the fault here is still mine, but maybe you could give me a hint at what I'm doing wrong so I can find a solution for this error, or possibly locate a new error within the SS collider. SAT+SS seems to be the most
efficient approach for me at the moment so I wouldn't really like to change.
2. On a side note I'm not pro in any way at optimizing code, but looking at code for removing arbiters associated with removed geoms I think there might be a faster solution. I might be dead wrong though, but it's just an idea as I would think it reduces
the amount of checks when removing several items at a time, also the check itself may be cheaper? The code also removes any arbiters associated with objects not currently in the simulation instead of just the recently removed items, which may clean up old
misses. (The old code is commented away for comparison)
for (int i = 0; i < _tempCount; i++)
_geomRemoveList[i].InSimulation = false;
// ORIGINAL CODE
////Remove any arbiters associated with the geometries being removed
//for (int j = ArbiterList.Count; j > 0; j--)
// if (ArbiterList[j - 1].GeometryA == _geomRemoveList[i] ||
// ArbiterList[j - 1].GeometryB == _geomRemoveList[i])
// //TODO: Should we create a RemoveComplete method and remove all Contacts associated
// //with the arbiter?
// arbiterPool.Insert(ArbiterList[j - 1]);
// ArbiterList.Remove(ArbiterList[j - 1]);
// NEW CODE
//Remove any arbiters associated with inactive geometries
if (_geomRemoveList.Count > 0)
for (int j = ArbiterList.Count; j > 0; j--)
if (!ArbiterList[j - 1].GeometryA.InSimulation ||
!ArbiterList[j - 1].GeometryB.InSimulation)
//TODO: Should we create a RemoveComplete method and remove all Contacts associated
//with the arbiter?
arbiterPool.Insert(ArbiterList[j - 1]);
ArbiterList.Remove(ArbiterList[j - 1]);