From 320982cae388814b8e7e9e9fe62724caa9621d90 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Thu, 9 Aug 2012 15:17:19 -0700 Subject: [PATCH] BulletSim: add an identifier to the TaintObject call so exceptions that happen when the taint is invoked can be debugged --- .../Physics/BulletSPlugin/BSCharacter.cs | 22 ++++----- .../Region/Physics/BulletSPlugin/BSLinkset.cs | 4 +- .../Region/Physics/BulletSPlugin/BSPrim.cs | 49 +++++++++---------- .../Region/Physics/BulletSPlugin/BSScene.cs | 34 ++++++++----- 4 files changed, 57 insertions(+), 52 deletions(-) diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index 8149a5359e..d49a578561 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs @@ -122,7 +122,7 @@ public class BSCharacter : PhysicsActor shapeData.Restitution = _scene.Params.avatarRestitution; // do actual create at taint time - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSCharacter.create", delegate() { BulletSimAPI.CreateObject(parent_scene.WorldID, shapeData); @@ -138,7 +138,7 @@ public class BSCharacter : PhysicsActor public void Destroy() { // DetailLog("{0},Destroy", LocalID); - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSCharacter.destroy", delegate() { BulletSimAPI.DestroyObject(_scene.WorldID, _localID); }); @@ -169,7 +169,7 @@ public class BSCharacter : PhysicsActor ComputeAvatarVolumeAndMass(); - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSCharacter.setSize", delegate() { BulletSimAPI.SetObjectScaleMass(_scene.WorldID, LocalID, _scale, _mass, true); }); @@ -207,7 +207,7 @@ public class BSCharacter : PhysicsActor _position = value; PositionSanityCheck(); - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSCharacter.setPosition", delegate() { DetailLog("{0},SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); @@ -246,7 +246,7 @@ public class BSCharacter : PhysicsActor set { _force = value; // m_log.DebugFormat("{0}: Force = {1}", LogHeader, _force); - Scene.TaintedObject(delegate() + Scene.TaintedObject("BSCharacter.SetForce", delegate() { DetailLog("{0},setForce,taint,force={1}", LocalID, _force); BulletSimAPI.SetObjectForce(Scene.WorldID, LocalID, _force); @@ -273,7 +273,7 @@ public class BSCharacter : PhysicsActor set { _velocity = value; // m_log.DebugFormat("{0}: set velocity = {1}", LogHeader, _velocity); - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSCharacter.setVelocity", delegate() { DetailLog("{0},setVelocity,taint,vel={1}", LocalID, _velocity); BulletSimAPI.SetObjectVelocity(_scene.WorldID, _localID, _velocity); @@ -299,7 +299,7 @@ public class BSCharacter : PhysicsActor set { _orientation = value; // m_log.DebugFormat("{0}: set orientation to {1}", LogHeader, _orientation); - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSCharacter.setOrientation", delegate() { // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); @@ -366,7 +366,7 @@ public class BSCharacter : PhysicsActor public override float Buoyancy { get { return _buoyancy; } set { _buoyancy = value; - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSCharacter.setBuoyancy", delegate() { DetailLog("{0},setBuoyancy,taint,buoy={1}", LocalID, _buoyancy); BulletSimAPI.SetObjectBuoyancy(_scene.WorldID, LocalID, _buoyancy); @@ -413,7 +413,7 @@ public class BSCharacter : PhysicsActor _force.Y += force.Y; _force.Z += force.Z; // m_log.DebugFormat("{0}: AddForce. adding={1}, newForce={2}", LogHeader, force, _force); - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSCharacter.AddForce", delegate() { DetailLog("{0},setAddForce,taint,addedForce={1}", LocalID, _force); BulletSimAPI.AddObjectForce2(Body.Ptr, _force); @@ -439,7 +439,7 @@ public class BSCharacter : PhysicsActor // make sure first collision happens _nextCollisionOkTime = Util.EnvironmentTickCount() - _subscribedEventsMs; - Scene.TaintedObject(delegate() + Scene.TaintedObject("BSCharacter.SubscribeEvents", delegate() { BulletSimAPI.AddToCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); }); @@ -449,7 +449,7 @@ public class BSCharacter : PhysicsActor public override void UnSubscribeEvents() { _subscribedEventsMs = 0; // Avatars get all their collision events - // Scene.TaintedObject(delegate() + // Scene.TaintedObject("BSCharacter.UnSubscribeEvents", delegate() // { // BulletSimAPI.RemoveFromCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); // }); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs index e265d6dcc8..bf262c5316 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs @@ -236,7 +236,7 @@ public class BSLinkset { m_children.Add(child); - m_scene.TaintedObject(delegate() + m_scene.TaintedObject("AddChildToLinkset", delegate() { DebugLog("{0}: AddChildToLinkset: adding child {1} to {2}", LogHeader, child.LocalID, m_linksetRoot.LocalID); DetailLog("{0},AddChildToLinkset,taint,child={1}", m_linksetRoot.LocalID, pchild.LocalID); @@ -265,7 +265,7 @@ public class BSLinkset if (m_children.Remove(child)) { - m_scene.TaintedObject(delegate() + m_scene.TaintedObject("RemoveChildFromLinkset", delegate() { DebugLog("{0}: RemoveChildFromLinkset: Removing constraint to {1}", LogHeader, child.LocalID); DetailLog("{0},RemoveChildFromLinkset,taint,child={1}", m_linksetRoot.LocalID, pchild.LocalID); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index e0f6ed22c3..988e03b9b6 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -145,7 +145,7 @@ public sealed class BSPrim : PhysicsActor _vehicle = new BSDynamics(this); // add vehicleness _mass = CalculateMass(); // do the actual object creation at taint time - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSPrim.create", delegate() { RecreateGeomAndObject(); @@ -166,7 +166,7 @@ public sealed class BSPrim : PhysicsActor _vehicle.ProcessTypeChange(Vehicle.TYPE_NONE); _scene.RemoveVehiclePrim(this); // just to make sure - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSPrim.destroy", delegate() { // Undo any links between me and any other object _linkset = _linkset.RemoveMeFromLinkset(this); @@ -183,7 +183,7 @@ public sealed class BSPrim : PhysicsActor get { return _size; } set { _size = value; - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSPrim.setSize", delegate() { _mass = CalculateMass(); // changing size changes the mass BulletSimAPI.SetObjectScaleMass(_scene.WorldID, _localID, _scale, (IsPhysical ? _mass : 0f), IsPhysical); @@ -195,7 +195,7 @@ public sealed class BSPrim : PhysicsActor public override PrimitiveBaseShape Shape { set { _pbs = value; - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSPrim.setShape", delegate() { _mass = CalculateMass(); // changing the shape changes the mass RecreateGeomAndObject(); @@ -213,7 +213,7 @@ public sealed class BSPrim : PhysicsActor public override bool Selected { set { _isSelected = value; - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSPrim.setSelected", delegate() { SetObjectDynamic(); }); @@ -281,7 +281,7 @@ public sealed class BSPrim : PhysicsActor set { _position = value; // TODO: what does it mean to set the position of a child prim?? Rebuild the constraint? - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSPrim.setPosition", delegate() { DetailLog("{0},SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); @@ -318,7 +318,7 @@ public sealed class BSPrim : PhysicsActor get { return _force; } set { _force = value; - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSPrim.setForce", delegate() { DetailLog("{0},setForce,taint,force={1}", LocalID, _force); // BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force); @@ -333,7 +333,7 @@ public sealed class BSPrim : PhysicsActor } set { Vehicle type = (Vehicle)value; - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSPrim.setVehicleType", delegate() { DetailLog("{0},SetVehicleType,taint,type={1}", LocalID, type); _vehicle.ProcessTypeChange(type); @@ -343,12 +343,7 @@ public sealed class BSPrim : PhysicsActor } else { - _scene.TaintedObject(delegate() - { - // Tell the physics engine to clear state - BulletSimAPI.ClearForces2(this.Body.Ptr); - }); - + BulletSimAPI.ClearForces2(this.Body.Ptr); // make it so the scene will call us each tick to do vehicle things _scene.AddVehiclePrim(this); } @@ -358,28 +353,28 @@ public sealed class BSPrim : PhysicsActor } public override void VehicleFloatParam(int param, float value) { - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSPrim.VehicleFloatParam", delegate() { _vehicle.ProcessFloatVehicleParam((Vehicle)param, value, _scene.LastSimulatedTimestep); }); } public override void VehicleVectorParam(int param, OMV.Vector3 value) { - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSPrim.VehicleVectorParam", delegate() { _vehicle.ProcessVectorVehicleParam((Vehicle)param, value, _scene.LastSimulatedTimestep); }); } public override void VehicleRotationParam(int param, OMV.Quaternion rotation) { - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSPrim.VehicleRotationParam", delegate() { _vehicle.ProcessRotationVehicleParam((Vehicle)param, rotation); }); } public override void VehicleFlags(int param, bool remove) { - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSPrim.VehicleFlags", delegate() { _vehicle.ProcessVehicleFlags(param, remove); }); @@ -397,7 +392,7 @@ public sealed class BSPrim : PhysicsActor public override void SetVolumeDetect(int param) { bool newValue = (param != 0); _isVolumeDetect = newValue; - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSPrim.SetVolumeDetect", delegate() { SetObjectDynamic(); }); @@ -408,7 +403,7 @@ public sealed class BSPrim : PhysicsActor get { return _velocity; } set { _velocity = value; - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSPrim.setVelocity", delegate() { DetailLog("{0},SetVelocity,taint,vel={1}", LocalID, _velocity); BulletSimAPI.SetObjectVelocity(_scene.WorldID, LocalID, _velocity); @@ -442,7 +437,7 @@ public sealed class BSPrim : PhysicsActor set { _orientation = value; // TODO: what does it mean if a child in a linkset changes its orientation? Rebuild the constraint? - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSPrim.setOrientation", delegate() { // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); DetailLog("{0},setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); @@ -459,7 +454,7 @@ public sealed class BSPrim : PhysicsActor get { return _isPhysical; } set { _isPhysical = value; - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSPrim.setIsPhysical", delegate() { SetObjectDynamic(); }); @@ -547,7 +542,7 @@ public sealed class BSPrim : PhysicsActor set { _rotationalVelocity = value; // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity); - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSPrim.setRotationalVelocity", delegate() { DetailLog("{0},SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); BulletSimAPI.SetObjectAngularVelocity(_scene.WorldID, LocalID, _rotationalVelocity); @@ -564,7 +559,7 @@ public sealed class BSPrim : PhysicsActor get { return _buoyancy; } set { _buoyancy = value; - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSPrim.setBuoyancy", delegate() { DetailLog("{0},SetBuoyancy,taint,buoy={1}", LocalID, _buoyancy); BulletSimAPI.SetObjectBuoyancy(_scene.WorldID, _localID, _buoyancy); @@ -618,7 +613,7 @@ public sealed class BSPrim : PhysicsActor m_log.WarnFormat("{0}: Got a NaN force applied to a Character", LogHeader); return; } - _scene.TaintedObject(delegate() + _scene.TaintedObject("BSPrim.AddForce", delegate() { OMV.Vector3 fSum = OMV.Vector3.Zero; lock (m_accumulatedForces) @@ -648,7 +643,7 @@ public sealed class BSPrim : PhysicsActor // make sure first collision happens _nextCollisionOkTime = Util.EnvironmentTickCount() - _subscribedEventsMs; - Scene.TaintedObject(delegate() + Scene.TaintedObject("BSPrim.SubscribeEvents", delegate() { BulletSimAPI.AddToCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); }); @@ -656,7 +651,7 @@ public sealed class BSPrim : PhysicsActor } public override void UnSubscribeEvents() { _subscribedEventsMs = 0; - Scene.TaintedObject(delegate() + Scene.TaintedObject("BSPrim.UnSubscribeEvents", delegate() { BulletSimAPI.RemoveFromCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); }); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index 117086ad4b..65a8014490 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs @@ -162,7 +162,17 @@ public class BSScene : PhysicsScene, IPhysicsParameters } public delegate void TaintCallback(); - private List _taintedObjects; + private struct TaintCallbackEntry + { + public String ident; + public TaintCallback callback; + public TaintCallbackEntry(string i, TaintCallback c) + { + ident = i; + callback = c; + } + } + private List _taintedObjects; private Object _taintLock = new Object(); // A pointer to an instance if this structure is passed to the C++ code @@ -232,7 +242,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters BulletSimAPI.SetDebugLogCallback(m_DebugLogCallbackHandle); } - _taintedObjects = new List(); + _taintedObjects = new List(); mesher = meshmerizer; // The bounding box for the simulated world @@ -535,7 +545,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters public override void SetTerrain(float[] heightMap) { m_heightMap = heightMap; - this.TaintedObject(delegate() + this.TaintedObject("BSScene.SetTerrain", delegate() { BulletSimAPI.SetHeightmap(m_worldID, m_heightMap); }); @@ -727,12 +737,12 @@ public class BSScene : PhysicsScene, IPhysicsParameters // Calls to the PhysicsActors can't directly call into the physics engine // because it might be busy. We delay changes to a known time. // We rely on C#'s closure to save and restore the context for the delegate. - public void TaintedObject(TaintCallback callback) + public void TaintedObject(String ident, TaintCallback callback) { if (!m_initialized) return; lock (_taintLock) - _taintedObjects.Add(callback); + _taintedObjects.Add(new TaintCallbackEntry(ident, callback)); return; } @@ -744,22 +754,22 @@ public class BSScene : PhysicsScene, IPhysicsParameters if (_taintedObjects.Count > 0) // save allocating new list if there is nothing to process { // swizzle a new list into the list location so we can process what's there - List oldList; + List oldList; lock (_taintLock) { oldList = _taintedObjects; - _taintedObjects = new List(); + _taintedObjects = new List(); } - foreach (TaintCallback callback in oldList) + foreach (TaintCallbackEntry tcbe in oldList) { try { - callback(); + tcbe.callback(); } catch (Exception e) { - m_log.ErrorFormat("{0}: ProcessTaints: Exception: {1}", LogHeader, e); + m_log.ErrorFormat("{0}: ProcessTaints: {1}: Exception: {2}", LogHeader, tcbe.ident, e); } } oldList.Clear(); @@ -1248,7 +1258,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters List objectIDs = lIDs; string xparm = parm.ToLower(); float xval = val; - TaintedObject(delegate() { + TaintedObject("BSScene.UpdateParameterSet", delegate() { foreach (uint lID in objectIDs) { BulletSimAPI.UpdateParameter(m_worldID, lID, xparm, xval); @@ -1268,7 +1278,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters uint xlocalID = localID; string xparm = parm.ToLower(); float xval = val; - TaintedObject(delegate() { + TaintedObject("BSScene.TaintedUpdateParameter", delegate() { BulletSimAPI.UpdateParameter(m_worldID, xlocalID, xparm, xval); }); }