From fe86df0ec9582c61ad3a50b53a73398393b13c87 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 9 Aug 2015 15:34:06 -0700 Subject: BulletSim: update the motion actors so they completely clean themselves when Dispose() is called. This reduces chance of object leakage when destroying objects. Rearrange initialization and shut down of BSActorLockAxis so it is consistant with other actors. --- .../Physics/BulletSPlugin/BSActorAvatarMove.cs | 3 +- .../Region/Physics/BulletSPlugin/BSActorHover.cs | 1 + .../Physics/BulletSPlugin/BSActorLockAxis.cs | 59 +++++++++++++--------- .../Physics/BulletSPlugin/BSActorMoveToTarget.cs | 1 + .../Physics/BulletSPlugin/BSActorSetForce.cs | 1 + .../Physics/BulletSPlugin/BSActorSetTorque.cs | 1 + OpenSim/Region/Physics/BulletSPlugin/BSActors.cs | 4 +- 7 files changed, 41 insertions(+), 29 deletions(-) (limited to 'OpenSim/Region/Physics') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs index c0d65be..bde4557 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorAvatarMove.cs @@ -71,8 +71,7 @@ public class BSActorAvatarMove : BSActor public override void Dispose() { base.SetEnabled(false); - // Now that turned off, remove any state we have in the scene. - Refresh(); + DeactivateAvatarMove(); } // Called when physical parameters (properties set in Bullet) need to be re-applied. diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorHover.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorHover.cs index 8a79809..e54c27b 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorHover.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorHover.cs @@ -58,6 +58,7 @@ public class BSActorHover : BSActor public override void Dispose() { Enabled = false; + DeactivateHover(); } // Called when physical parameters (properties set in Bullet) need to be re-applied. diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs index 48cab64..3b3c161 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs @@ -36,7 +36,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin { public class BSActorLockAxis : BSActor { - BSConstraint LockAxisConstraint = null; + private BSConstraint LockAxisConstraint = null; + private bool HaveRegisteredForBeforeStepCallback = false; + // The lock access flags (which axises were locked) when the contraint was built. // Used to see if locking has changed since when the constraint was built. OMV.Vector3 LockAxisLinearFlags; @@ -47,9 +49,7 @@ public class BSActorLockAxis : BSActor { m_physicsScene.DetailLog("{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID); LockAxisConstraint = null; - - // we place our constraint just before the simulation step to make sure the linkset is complete - m_physicsScene.BeforeStep += PhysicsScene_BeforeStep; + HaveRegisteredForBeforeStepCallback = false; } // BSActor.isActive @@ -62,7 +62,8 @@ public class BSActorLockAxis : BSActor // BSActor.Dispose() public override void Dispose() { - m_physicsScene.BeforeStep -= PhysicsScene_BeforeStep; + Enabled = false; + UnRegisterForBeforeStepCallback(); RemoveAxisLockConstraint(); } @@ -74,37 +75,26 @@ public class BSActorLockAxis : BSActor // Since the axis logging is done with a constraint, Refresh() time is good for // changing parameters but this needs to wait until the prim/linkset is physically // constructed. Therefore, the constraint itself is placed at pre-step time. - /* - m_physicsScene.DetailLog("{0},BSActorLockAxis,refresh,lockedLinear={1},lockedAngular={2},enabled={3},pActive={4}", - m_controllingPrim.LocalID, - m_controllingPrim.LockedLinearAxis, - m_controllingPrim.LockedAngularAxis, - Enabled, m_controllingPrim.IsPhysicallyActive); + // If all the axis are free, we don't need to exist + // Refresh() only turns off. Enabling is done by InitializeAxisActor() + // whenever parameters are changed. + // This leaves 'enable' free to turn off an actor when it is not wanted to run. if (m_controllingPrim.LockedAngularAxis == m_controllingPrim.LockedAxisFree && m_controllingPrim.LockedLinearAxis == m_controllingPrim.LockedAxisFree) { Enabled = false; } - // If the object is physically active, add the axis locking constraint if (isActive) { - // Check to see if the locking parameters have changed - if (m_controllingPrim.LockedLinearAxis != this.LockAxisLinearFlags - || m_controllingPrim.LockedAngularAxis != this.LockAxisAngularFlags) - { - // The locking has changed. Remove the old constraint and build a new one - RemoveAxisLockConstraint(); - } - - AddAxisLockConstraint(); + RegisterForBeforeStepCallback(); } else { - RemoveAxisLockConstraint(); + RemoveDependencies(); + UnRegisterForBeforeStepCallback(); } - */ } // The object's physical representation is being rebuilt so pick up any physical dependencies (constraints, ...). @@ -114,7 +104,24 @@ public class BSActorLockAxis : BSActor public override void RemoveDependencies() { RemoveAxisLockConstraint(); - // The pre-step action will restore the constraint of needed + } + + private void RegisterForBeforeStepCallback() + { + if (!HaveRegisteredForBeforeStepCallback) + { + m_physicsScene.BeforeStep += PhysicsScene_BeforeStep; + HaveRegisteredForBeforeStepCallback = true; + } + } + + private void UnRegisterForBeforeStepCallback() + { + if (HaveRegisteredForBeforeStepCallback) + { + m_physicsScene.BeforeStep -= PhysicsScene_BeforeStep; + HaveRegisteredForBeforeStepCallback = false; + } } private void PhysicsScene_BeforeStep(float timestep) @@ -145,6 +152,7 @@ public class BSActorLockAxis : BSActor } } + // Note that this relies on being called at TaintTime private void AddAxisLockConstraint() { if (LockAxisConstraint == null) @@ -192,11 +200,14 @@ public class BSActorLockAxis : BSActor axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f); axisConstrainer.RecomputeConstraintVariables(m_controllingPrim.RawMass); + + RegisterForBeforeStepCallback(); } } private void RemoveAxisLockConstraint() { + UnRegisterForBeforeStepCallback(); if (LockAxisConstraint != null) { m_physicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorMoveToTarget.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorMoveToTarget.cs index bdf4bc0..1145006 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorMoveToTarget.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorMoveToTarget.cs @@ -59,6 +59,7 @@ public class BSActorMoveToTarget : BSActor public override void Dispose() { Enabled = false; + DeactivateMoveToTarget(); } // Called when physical parameters (properties set in Bullet) need to be re-applied. diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorSetForce.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorSetForce.cs index 96fa0b6..4e81363 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorSetForce.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorSetForce.cs @@ -58,6 +58,7 @@ public class BSActorSetForce : BSActor public override void Dispose() { Enabled = false; + DeactivateSetForce(); } // Called when physical parameters (properties set in Bullet) need to be re-applied. diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorSetTorque.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorSetTorque.cs index 65098e1..79e1d38 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorSetTorque.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorSetTorque.cs @@ -58,6 +58,7 @@ public class BSActorSetTorque : BSActor public override void Dispose() { Enabled = false; + DeactivateSetTorque(); } // Called when physical parameters (properties set in Bullet) need to be re-applied. diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs index e0ccc50..7f45e2c 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs @@ -32,12 +32,10 @@ namespace OpenSim.Region.Physics.BulletSPlugin { public class BSActorCollection { - private BSScene m_physicsScene { get; set; } private Dictionary m_actors; - public BSActorCollection(BSScene physicsScene) + public BSActorCollection() { - m_physicsScene = physicsScene; m_actors = new Dictionary(); } public void Add(string name, BSActor actor) -- cgit v1.1