refactor: centralize prim geom removal code from four places to one

bulletsim
Justin Clark-Casey (justincc) 2011-08-01 06:15:02 +01:00
parent 509200d5cd
commit 6618948ff9
3 changed files with 48 additions and 43 deletions

View File

@ -86,6 +86,10 @@ namespace OpenSim.Region.Physics.Manager
public abstract void RemoveAvatar(PhysicsActor actor); public abstract void RemoveAvatar(PhysicsActor actor);
/// <summary>
/// Remove a prim from the physics scene.
/// </summary>
/// <param name="prim"></param>
public abstract void RemovePrim(PhysicsActor prim); public abstract void RemovePrim(PhysicsActor prim);
public abstract PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, public abstract PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,

View File

@ -1352,7 +1352,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <param name="m_targetSpace"></param> /// <param name="m_targetSpace"></param>
/// <param name="mesh">If null, then a mesh is used that is based on the profile shape data.</param> /// <param name="mesh">If null, then a mesh is used that is based on the profile shape data.</param>
@ -1436,6 +1436,36 @@ Console.WriteLine("CreateGeom:");
} }
} }
/// <summary>
/// Remove the existing geom from this prim.
/// </summary>
/// <param name="m_targetSpace"></param>
/// <param name="mesh">If null, then a mesh is used that is based on the profile shape data.</param>
/// <returns>true if the geom was successfully removed, false if it was already gone or the remove failed.</returns>
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) public void changeadd(float timestep)
{ {
int[] iprimspaceArrItem = _parent_scene.calculateSpaceArrayItemFromPos(_position); int[] iprimspaceArrItem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
@ -1880,19 +1910,8 @@ Console.WriteLine(" JointCreateFixed");
{ {
if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim) if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim)
{ {
if (prim_geom != IntPtr.Zero) RemoveGeom();
{
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);
}
}
//Console.WriteLine("changePhysicsStatus for " + Name); //Console.WriteLine("changePhysicsStatus for " + Name);
changeadd(2f); changeadd(2f);
} }
@ -1953,8 +1972,8 @@ Console.WriteLine(" JointCreateFixed");
d.SpaceRemove(m_targetSpace, prim_geom); d.SpaceRemove(m_targetSpace, prim_geom);
} }
d.GeomDestroy(prim_geom); RemoveGeom();
prim_geom = IntPtr.Zero;
// we don't need to do space calculation because the client sends a position update also. // we don't need to do space calculation because the client sends a position update also.
IMesh mesh = null; IMesh mesh = null;
@ -2044,17 +2063,9 @@ Console.WriteLine(" JointCreateFixed");
disableBody(); 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. // 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.X <= 0) _size.X = 0.01f;
if (_size.Y <= 0) _size.Y = 0.01f; if (_size.Y <= 0) _size.Y = 0.01f;

View File

@ -2094,6 +2094,8 @@ namespace OpenSim.Region.Physics.OdePlugin
public override void RemovePrim(PhysicsActor prim) 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) if (prim is OdePrim)
{ {
lock (OdeLock) lock (OdeLock)
@ -2169,24 +2171,12 @@ namespace OpenSim.Region.Physics.OdePlugin
//} //}
//} //}
//m_log.Warn(prim.prim_geom); //m_log.Warn(prim.prim_geom);
try
{ if (!prim.RemoveGeom())
if (prim.prim_geom != IntPtr.Zero) m_log.Warn("[PHYSICS]: Unable to remove prim from physics scene");
{
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.");
}
lock (_prims) 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 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) //if (d.SpaceGetNumGeoms(prim.m_targetSpace) == 0)