From 4e1ca890c2d41bf244ed7d4847c0d0a4fc7f6c51 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 14 Jan 2013 15:46:46 -0800 Subject: 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. --- .../Region/Physics/BulletSPlugin/BSPhysObject.cs | 29 ++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index 185f111..821f470 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs @@ -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 kvp in RegisteredActions) + lock (RegisteredActions) { - PhysicsScene.BeforeStep -= kvp.Value; + foreach (KeyValuePair kvp in RegisteredActions) + { + PhysicsScene.BeforeStep -= kvp.Value; + } + RegisteredActions.Clear(); } - RegisteredActions.Clear(); DetailLog("{0},BSPhysObject.UnRegisterAllPreStepActions,", LocalID); } -- cgit v1.1