BulletSim: fix not moving physical objects below terrain to over terrain.

Add locking on register prestep action list preventing potential race conditions.
Little comment and formatting changes.
This commit is contained in:
Robert Adams
2013-01-14 15:46:46 -08:00
parent 8bf0a9f85d
commit 4e1ca890c2
5 changed files with 36 additions and 18 deletions

View File

@@ -382,10 +382,13 @@ public abstract class BSPhysObject : PhysicsActor
{
string identifier = op + "-" + id.ToString();
// Clean out any existing action
UnRegisterPreStepAction(op, id);
lock (RegisteredActions)
{
// Clean out any existing action
UnRegisterPreStepAction(op, id);
RegisteredActions[identifier] = actn;
RegisteredActions[identifier] = actn;
}
PhysicsScene.BeforeStep += actn;
DetailLog("{0},BSPhysObject.RegisterPreStepAction,id={1}", LocalID, identifier);
}
@@ -395,22 +398,28 @@ public abstract class BSPhysObject : PhysicsActor
{
string identifier = op + "-" + id.ToString();
bool removed = false;
if (RegisteredActions.ContainsKey(identifier))
lock (RegisteredActions)
{
PhysicsScene.BeforeStep -= RegisteredActions[identifier];
RegisteredActions.Remove(identifier);
removed = true;
if (RegisteredActions.ContainsKey(identifier))
{
PhysicsScene.BeforeStep -= RegisteredActions[identifier];
RegisteredActions.Remove(identifier);
removed = true;
}
}
DetailLog("{0},BSPhysObject.UnRegisterPreStepAction,id={1},removed={2}", LocalID, identifier, removed);
}
protected void UnRegisterAllPreStepActions()
{
foreach (KeyValuePair<string, BSScene.PreStepAction> kvp in RegisteredActions)
lock (RegisteredActions)
{
PhysicsScene.BeforeStep -= kvp.Value;
foreach (KeyValuePair<string, BSScene.PreStepAction> kvp in RegisteredActions)
{
PhysicsScene.BeforeStep -= kvp.Value;
}
RegisteredActions.Clear();
}
RegisteredActions.Clear();
DetailLog("{0},BSPhysObject.UnRegisterAllPreStepActions,", LocalID);
}