From 87733b196bdc36a21aee775860c962c1141d44af Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Fri, 1 Mar 2019 11:48:00 +0000 Subject: [PATCH] reduce the chance of using a invalid avatar physics actor --- .../Region/Framework/Scenes/ScenePresence.cs | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index f3e217906c..1c5d23d9b4 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -507,7 +507,19 @@ namespace OpenSim.Region.Framework.Scenes /// /// Physical scene representation of this Avatar. /// - public PhysicsActor PhysicsActor { get; private set; } + + PhysicsActor m_physActor; + public PhysicsActor PhysicsActor + { + get + { + return m_physActor; + } + private set + { + m_physActor = value; + } + } /// /// Record user movement inputs. @@ -1641,15 +1653,15 @@ namespace OpenSim.Region.Framework.Scenes /// public void RemoveFromPhysicalScene() { - if (PhysicsActor != null) + PhysicsActor pa = Interlocked.Exchange(ref m_physActor, null); + if (pa != null) { // PhysicsActor.OnRequestTerseUpdate -= SendTerseUpdateToAllClients; - PhysicsActor.OnOutOfBounds -= OutOfBoundsCall; - PhysicsActor.OnCollisionUpdate -= PhysicsCollisionUpdate; - PhysicsActor.UnSubscribeEvents(); - m_scene.PhysicsScene.RemoveAvatar(PhysicsActor); - PhysicsActor = null; + pa.OnOutOfBounds -= OutOfBoundsCall; + pa.OnCollisionUpdate -= PhysicsCollisionUpdate; + pa.UnSubscribeEvents(); + m_scene.PhysicsScene.RemoveAvatar(pa); } // else // { @@ -2542,7 +2554,7 @@ namespace OpenSim.Region.Framework.Scenes m_pos.X = 127f; m_pos.Y = 127f; m_pos.Z = 127f; - m_log.Error("[AVATAR]: NonFinite Avatar position detected... Reset Position. Mantis this please. Error #9999903"); + m_log.Error("[AVATAR]: NonFinite Avatar on lastFiniteposition also. Reset Position. Mantis this please. Error #9999903"); } if(isphysical) @@ -5012,16 +5024,17 @@ namespace OpenSim.Region.Framework.Scenes PhysicsScene scene = m_scene.PhysicsScene; Vector3 pVec = AbsolutePosition; - PhysicsActor = scene.AddAvatar( + PhysicsActor pa = scene.AddAvatar( LocalId, Firstname + "." + Lastname, pVec, Appearance.AvatarBoxSize,Appearance.AvatarFeetOffset, isFlying); - PhysicsActor.Orientation = m_bodyRot; + pa.Orientation = m_bodyRot; //PhysicsActor.OnRequestTerseUpdate += SendTerseUpdateToAllClients; - PhysicsActor.OnCollisionUpdate += PhysicsCollisionUpdate; - PhysicsActor.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong - PhysicsActor.SubscribeEvents(100); - PhysicsActor.LocalID = LocalId; - PhysicsActor.SetAlwaysRun = m_setAlwaysRun; + pa.OnCollisionUpdate += PhysicsCollisionUpdate; + pa.OnOutOfBounds += OutOfBoundsCall; // Called for PhysicsActors when there's something wrong + pa.SubscribeEvents(100); + pa.LocalID = LocalId; + pa.SetAlwaysRun = m_setAlwaysRun; + PhysicsActor = pa; } private void OutOfBoundsCall(Vector3 pos)