From d06b75fe3b010347e100a132daa716b6498e5c0b Mon Sep 17 00:00:00 2001 From: dahlia Date: Thu, 8 Jul 2010 11:10:08 -0700 Subject: fix a potential division by zero --- OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs index 941c761..bb5267c 100644 --- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs +++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs @@ -259,10 +259,15 @@ namespace OpenSim.Region.ScriptEngine.Shared return Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z); } - public static Vector3 Norm(Vector3 vector) - { - double mag = Mag(vector); - return new Vector3(vector.x / mag, vector.y / mag, vector.z / mag); + public static Vector3 Norm(Vector3 vector) + { + double mag = Mag(vector); + if (mag > 0.0) + { + double invMag = 1.0 / mag; + return vector * invMag; + } + return new Vector3(0, 0, 0); } #endregion -- cgit v1.1