Reinsert PhysicsActor variable back into SOP.SubscribeForCollisionEvents() in order to avoid a race condition.

A separate PhysicsActor variable is used in case some other thread removes the PhysicsActor whilst this code is executing.
If this is now impossible please revert - just adding this now whilst I remember.
Also makes method comment into proper method doc.
cpu-performance
Justin Clark-Casey (justincc) 2013-07-13 00:29:07 +01:00
parent b4cb644a05
commit d06c85ea77
1 changed files with 12 additions and 8 deletions

View File

@ -4272,10 +4272,14 @@ namespace OpenSim.Region.Framework.Scenes
// m_log.DebugFormat("[SCENE OBJECT PART]: Updated PrimFlags on {0} {1} to {2}", Name, LocalId, Flags);
}
// Subscribe for physics collision events if needed for scripts and sounds
/// <summary>
/// Subscribe for physics collision events if needed for scripts and sounds
/// </summary>
public void SubscribeForCollisionEvents()
{
if (PhysActor != null)
PhysicsActor pa = PhysActor;
if (pa != null)
{
if (
((AggregateScriptEvents & scriptEvents.collision) != 0) ||
@ -4293,20 +4297,20 @@ namespace OpenSim.Region.Framework.Scenes
(CollisionSound != UUID.Zero)
)
{
if (!PhysActor.SubscribedEvents())
if (!pa.SubscribedEvents())
{
// If not already subscribed for event, set up for a collision event.
PhysActor.OnCollisionUpdate += PhysicsCollision;
PhysActor.SubscribeEvents(1000);
pa.OnCollisionUpdate += PhysicsCollision;
pa.SubscribeEvents(1000);
}
}
else
{
// There is no need to be subscribed to collisions so, if subscribed, remove subscription
if (PhysActor.SubscribedEvents())
if (pa.SubscribedEvents())
{
PhysActor.OnCollisionUpdate -= PhysicsCollision;
PhysActor.UnSubscribeEvents();
pa.OnCollisionUpdate -= PhysicsCollision;
pa.UnSubscribeEvents();
}
}
}