From 592f98c4aaa5265a31c481a49cfc7afb49590da3 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Fri, 19 Sep 2008 17:00:17 +0000 Subject: Mantis #2217 Guard against NaN being returned from llRotBetween. Return a zero rotation if the result is NaN. --- OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs | 10 +++++++++- .../Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs index 2eb50ef..dbb61fd 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs @@ -562,7 +562,15 @@ namespace OpenSim.Region.ScriptEngine.Common LSL_Types.Vector3 axis = LSL_Types.Vector3.Norm(crossProduct); double s = Math.Sin(angle / 2); - return new LSL_Types.Quaternion(axis.x * s, axis.y * s, axis.z * s, (float)Math.Cos(angle / 2)); + double x = axis.x * s; + double y = axis.y * s; + double z = axis.z * s; + double w = Math.Cos(angle / 2); + + if(Double.IsNaN(x) || Double.IsNaN(y) || Double.IsNaN(z) || Double.IsNaN(w)) + return new LSL_Types.Quaternion(0.0f, 0.0f, 0.0f, 1.0f); + + return new LSL_Types.Quaternion((float)x, (float)y, (float)z, (float)w); } public void llWhisper(int channelID, string text) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 758cf4b..bff63f1 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -581,7 +581,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api LSL_Types.Vector3 axis = LSL_Types.Vector3.Norm(crossProduct); double s = Math.Sin(angle / 2); - return new LSL_Types.Quaternion(axis.x * s, axis.y * s, axis.z * s, (float)Math.Cos(angle / 2)); + double x = axis.x * s; + double y = axis.y * s; + double z = axis.z * s; + double w = Math.Cos(angle / 2); + + if(Double.IsNaN(x) || Double.IsNaN(y) || Double.IsNaN(z) || Double.IsNaN(w)) + return new LSL_Types.Quaternion(0.0f, 0.0f, 0.0f, 1.0f); + + return new LSL_Types.Quaternion((float)x, (float)y, (float)z, (float)w); } public void llWhisper(int channelID, string text) -- cgit v1.1