From 6618948ff9b1e98b52f3067855ca1b05e7e36144 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Mon, 1 Aug 2011 06:15:02 +0100 Subject: [PATCH] refactor: centralize prim geom removal code from four places to one --- .../Region/Physics/Manager/PhysicsScene.cs | 4 ++ OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 63 +++++++++++-------- OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 24 +++---- 3 files changed, 48 insertions(+), 43 deletions(-) diff --git a/OpenSim/Region/Physics/Manager/PhysicsScene.cs b/OpenSim/Region/Physics/Manager/PhysicsScene.cs index 3870411427..04efc1dca1 100644 --- a/OpenSim/Region/Physics/Manager/PhysicsScene.cs +++ b/OpenSim/Region/Physics/Manager/PhysicsScene.cs @@ -86,6 +86,10 @@ namespace OpenSim.Region.Physics.Manager public abstract void RemoveAvatar(PhysicsActor actor); + /// + /// Remove a prim from the physics scene. + /// + /// public abstract void RemovePrim(PhysicsActor prim); public abstract PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 61408f0ab2..e90df4888f 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -1352,7 +1352,7 @@ Console.WriteLine("ZProcessTaints for " + Name); } /// - /// Create a geometry for the given mesh/shape in the given target space. + /// Create a geometry for the given mesh in the given target space. /// /// /// If null, then a mesh is used that is based on the profile shape data. @@ -1436,6 +1436,36 @@ Console.WriteLine("CreateGeom:"); } } + /// + /// Remove the existing geom from this prim. + /// + /// + /// If null, then a mesh is used that is based on the profile shape data. + /// true if the geom was successfully removed, false if it was already gone or the remove failed. + public bool RemoveGeom() + { + if (prim_geom != IntPtr.Zero) + { + try + { + d.GeomDestroy(prim_geom); + prim_geom = IntPtr.Zero; + } + catch (System.AccessViolationException) + { + prim_geom = IntPtr.Zero; + m_log.ErrorFormat("[PHYSICS]: PrimGeom dead for {0}", Name); + return false; + } + + return true; + } + else + { + return false; + } + } + public void changeadd(float timestep) { int[] iprimspaceArrItem = _parent_scene.calculateSpaceArrayItemFromPos(_position); @@ -1880,19 +1910,8 @@ Console.WriteLine(" JointCreateFixed"); { if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim) { - if (prim_geom != IntPtr.Zero) - { - try - { - d.GeomDestroy(prim_geom); - prim_geom = IntPtr.Zero; - } - catch (System.AccessViolationException) - { - prim_geom = IntPtr.Zero; - m_log.ErrorFormat("[PHYSICS]: PrimGeom dead for {0}", Name); - } - } + RemoveGeom(); + //Console.WriteLine("changePhysicsStatus for " + Name); changeadd(2f); } @@ -1953,8 +1972,8 @@ Console.WriteLine(" JointCreateFixed"); d.SpaceRemove(m_targetSpace, prim_geom); } - d.GeomDestroy(prim_geom); - prim_geom = IntPtr.Zero; + RemoveGeom(); + // we don't need to do space calculation because the client sends a position update also. IMesh mesh = null; @@ -2044,17 +2063,9 @@ Console.WriteLine(" JointCreateFixed"); disableBody(); } } - try - { - d.GeomDestroy(prim_geom); - } - catch (System.AccessViolationException) - { - prim_geom = IntPtr.Zero; - m_log.ErrorFormat("[PHYSICS]: PrimGeom dead for {0}", Name); - } - prim_geom = IntPtr.Zero; + RemoveGeom(); + // we don't need to do space calculation because the client sends a position update also. if (_size.X <= 0) _size.X = 0.01f; if (_size.Y <= 0) _size.Y = 0.01f; diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index 4419dff790..3402be2975 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs @@ -2094,6 +2094,8 @@ namespace OpenSim.Region.Physics.OdePlugin public override void RemovePrim(PhysicsActor prim) { + // As with all ODE physics operations, we don't remove the prim immediately but signal that it should be + // removed in the next physics simulate pass. if (prim is OdePrim) { lock (OdeLock) @@ -2169,24 +2171,12 @@ namespace OpenSim.Region.Physics.OdePlugin //} //} //m_log.Warn(prim.prim_geom); - try - { - if (prim.prim_geom != IntPtr.Zero) - { - d.GeomDestroy(prim.prim_geom); - prim.prim_geom = IntPtr.Zero; - } - else - { - m_log.Warn("[PHYSICS]: Unable to remove prim from physics scene"); - } - } - catch (AccessViolationException) - { - m_log.Info("[PHYSICS]: Couldn't remove prim from physics scene, it was already be removed."); - } + + if (!prim.RemoveGeom()) + m_log.Warn("[PHYSICS]: Unable to remove prim from physics scene"); + lock (_prims) - _prims.Remove(prim); + _prims.Remove(prim); //If there are no more geometries in the sub-space, we don't need it in the main space anymore //if (d.SpaceGetNumGeoms(prim.m_targetSpace) == 0)