From 8b2af1071f37e45dc330524a4731581867616b21 Mon Sep 17 00:00:00 2001 From: dahlia Date: Mon, 16 Feb 2015 23:51:37 -0800 Subject: [PATCH] Add NaN and Infinity tests for SOP Velocity and Acceleration setters. --- OpenSim/Framework/Util.cs | 16 ++++++++++++++++ .../Region/Framework/Scenes/SceneObjectPart.cs | 18 +++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 836fa5fcaa..56a90b1b5d 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -420,6 +420,22 @@ namespace OpenSim.Framework return x; } + /// + /// Check if any of the values in a Vector3 are NaN or Infinity + /// + /// Vector3 to check + /// + public static bool IsNanOrInfinity(Vector3 v) + { + if (float.IsNaN(v.X) || float.IsNaN(v.Y) || float.IsNaN(v.Z)) + return true; + + if (float.IsInfinity(v.X) || float.IsInfinity(v.Y) || float.IsNaN(v.Z)) + return true; + + return false; + } + // Inclusive, within range test (true if equal to the endpoints) public static bool InRange(T x, T min, T max) where T : IComparable diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 4a8be4255a..57ec1ae291 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -929,14 +929,17 @@ namespace OpenSim.Region.Framework.Scenes set { - m_velocity = value; + if (Util.IsNanOrInfinity(value)) + m_velocity = Vector3.Zero; + else + m_velocity = value; PhysicsActor actor = PhysActor; if (actor != null) { if (actor.IsPhysical) { - actor.Velocity = value; + actor.Velocity = m_velocity; ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor); } } @@ -965,8 +968,7 @@ namespace OpenSim.Region.Framework.Scenes } set { - if (float.IsNaN(value.X) || float.IsNaN(value.Y) || float.IsNaN(value.Z) - || float.IsInfinity(value.X) || float.IsInfinity(value.Y) || float.IsInfinity(value.Z)) + if (Util.IsNanOrInfinity(value)) m_angularVelocity = Vector3.Zero; else m_angularVelocity = value; @@ -981,7 +983,13 @@ namespace OpenSim.Region.Framework.Scenes public Vector3 Acceleration { get { return m_acceleration; } - set { m_acceleration = value; } + set + { + if (Util.IsNanOrInfinity(value)) + m_acceleration = Vector3.Zero; + else + m_acceleration = value; + } } public string Description { get; set; }