refactor: centralize prim geom removal code from four places to one
parent
509200d5cd
commit
6618948ff9
|
@ -86,6 +86,10 @@ namespace OpenSim.Region.Physics.Manager
|
|||
|
||||
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 PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
|
||||
|
|
|
@ -1352,7 +1352,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
|
|||
}
|
||||
|
||||
/// <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>
|
||||
/// <param name="m_targetSpace"></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)
|
||||
{
|
||||
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;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue