remove possible PhysActor unexpectedly null race conditions when changing prim collision status
factor out common SOP physics scene adding code into a common SOP.AddToPhysics() that is the counterpart to the existing RemoveFromPhysics()0.7.3-extended
parent
54e59099b7
commit
84d4b390f1
|
@ -2163,12 +2163,6 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (rootPart.PhysActor != null)
|
|
||||||
// {
|
|
||||||
// PhysicsScene.RemovePrim(rootPart.PhysActor);
|
|
||||||
// rootPart.PhysActor = null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (UnlinkSceneObject(group, false))
|
if (UnlinkSceneObject(group, false))
|
||||||
{
|
{
|
||||||
EventManager.TriggerObjectBeingRemovedFromScene(group);
|
EventManager.TriggerObjectBeingRemovedFromScene(group);
|
||||||
|
|
|
@ -1488,40 +1488,17 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
if (VolumeDetectActive)
|
if (VolumeDetectActive)
|
||||||
isPhantom = false;
|
isPhantom = false;
|
||||||
|
|
||||||
// Added clarification.. since A rigid body is an object that you can kick around, etc.
|
|
||||||
bool RigidBody = isPhysical && !isPhantom;
|
|
||||||
|
|
||||||
// The only time the physics scene shouldn't know about the prim is if it's phantom or an attachment, which is phantom by definition
|
// The only time the physics scene shouldn't know about the prim is if it's phantom or an attachment, which is phantom by definition
|
||||||
// or flexible
|
// or flexible
|
||||||
if (!isPhantom && !ParentGroup.IsAttachment && !(Shape.PathCurve == (byte)Extrusion.Flexible))
|
if (!isPhantom && !ParentGroup.IsAttachment && !(Shape.PathCurve == (byte)Extrusion.Flexible))
|
||||||
{
|
{
|
||||||
try
|
// Added clarification.. since A rigid body is an object that you can kick around, etc.
|
||||||
{
|
bool rigidBody = isPhysical && !isPhantom;
|
||||||
PhysActor = ParentGroup.Scene.PhysicsScene.AddPrimShape(
|
|
||||||
string.Format("{0}/{1}", Name, UUID),
|
|
||||||
Shape,
|
|
||||||
AbsolutePosition,
|
|
||||||
Scale,
|
|
||||||
RotationOffset,
|
|
||||||
RigidBody,
|
|
||||||
m_localId);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
m_log.ErrorFormat("[SCENE]: caught exception meshing object {0}. Object set to phantom.", m_uuid);
|
|
||||||
PhysActor = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Basic Physics can also return null as well as an exception catch.
|
PhysicsActor pa = AddToPhysics(rigidBody);
|
||||||
PhysicsActor pa = PhysActor;
|
|
||||||
|
|
||||||
if (pa != null)
|
if (pa != null)
|
||||||
{
|
|
||||||
pa.SOPName = this.Name; // save object into the PhysActor so ODE internals know the joint/body info
|
|
||||||
pa.SetMaterial(Material);
|
|
||||||
DoPhysicsPropertyUpdate(RigidBody, true);
|
|
||||||
pa.SetVolumeDetect(VolumeDetectActive ? 1 : 0);
|
pa.SetVolumeDetect(VolumeDetectActive ? 1 : 0);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4325,41 +4302,36 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
if (ParentGroup.Scene == null)
|
if (ParentGroup.Scene == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (ParentGroup.Scene.CollidablePrims && PhysActor == null)
|
if (ParentGroup.Scene.CollidablePrims && pa == null)
|
||||||
{
|
{
|
||||||
// It's not phantom anymore. So make sure the physics engine get's knowledge of it
|
pa = AddToPhysics(UsePhysics);
|
||||||
PhysActor = ParentGroup.Scene.PhysicsScene.AddPrimShape(
|
|
||||||
string.Format("{0}/{1}", Name, UUID),
|
|
||||||
Shape,
|
|
||||||
AbsolutePosition,
|
|
||||||
Scale,
|
|
||||||
RotationOffset,
|
|
||||||
UsePhysics,
|
|
||||||
m_localId);
|
|
||||||
|
|
||||||
PhysActor.SetMaterial(Material);
|
if (pa != null)
|
||||||
DoPhysicsPropertyUpdate(UsePhysics, true);
|
|
||||||
|
|
||||||
if (!ParentGroup.IsDeleted)
|
|
||||||
{
|
{
|
||||||
if (LocalId == ParentGroup.RootPart.LocalId)
|
pa.SetMaterial(Material);
|
||||||
|
DoPhysicsPropertyUpdate(UsePhysics, true);
|
||||||
|
|
||||||
|
if (!ParentGroup.IsDeleted)
|
||||||
{
|
{
|
||||||
ParentGroup.CheckSculptAndLoad();
|
if (LocalId == ParentGroup.RootPart.LocalId)
|
||||||
|
{
|
||||||
|
ParentGroup.CheckSculptAndLoad();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
((AggregateScriptEvents & scriptEvents.collision) != 0) ||
|
((AggregateScriptEvents & scriptEvents.collision) != 0) ||
|
||||||
((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
|
((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
|
||||||
((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
|
((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
|
||||||
((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
|
((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
|
||||||
((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
|
((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
|
||||||
((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
|
((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
|
||||||
(CollisionSound != UUID.Zero)
|
(CollisionSound != UUID.Zero)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
PhysActor.OnCollisionUpdate += PhysicsCollision;
|
pa.OnCollisionUpdate += PhysicsCollision;
|
||||||
PhysActor.SubscribeEvents(1000);
|
pa.SubscribeEvents(1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // it already has a physical representation
|
else // it already has a physical representation
|
||||||
|
@ -4421,7 +4393,52 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This removes the part from physics
|
/// Adds this part to the physics scene.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>This method also sets the PhysActor property.</remarks>
|
||||||
|
/// <param name="rigidBody">Add this prim with a rigid body.</param>
|
||||||
|
/// <returns>
|
||||||
|
/// The physics actor. null if there was a failure.
|
||||||
|
/// </returns>
|
||||||
|
private PhysicsActor AddToPhysics(bool rigidBody)
|
||||||
|
{
|
||||||
|
PhysicsActor pa;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
pa = ParentGroup.Scene.PhysicsScene.AddPrimShape(
|
||||||
|
string.Format("{0}/{1}", Name, UUID),
|
||||||
|
Shape,
|
||||||
|
AbsolutePosition,
|
||||||
|
Scale,
|
||||||
|
RotationOffset,
|
||||||
|
rigidBody,
|
||||||
|
m_localId);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_log.ErrorFormat("[SCENE]: caught exception meshing object {0}. Object set to phantom.", m_uuid);
|
||||||
|
pa = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Ideally we wouldn't set the property here to reduce situations where threads changing physical
|
||||||
|
// properties can stop on each other. However, DoPhysicsPropertyUpdate() currently relies on PhysActor
|
||||||
|
// being set.
|
||||||
|
PhysActor = pa;
|
||||||
|
|
||||||
|
// Basic Physics can also return null as well as an exception catch.
|
||||||
|
if (pa != null)
|
||||||
|
{
|
||||||
|
pa.SOPName = this.Name; // save object into the PhysActor so ODE internals know the joint/body info
|
||||||
|
pa.SetMaterial(Material);
|
||||||
|
DoPhysicsPropertyUpdate(rigidBody, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pa;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This removes the part from the physics scene.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// This isn't the same as turning off physical, since even without being physical the prim has a physics
|
/// This isn't the same as turning off physical, since even without being physical the prim has a physics
|
||||||
|
|
Loading…
Reference in New Issue