From 2de1aea17380e872b81eba98a0ec37fbbcb605ec Mon Sep 17 00:00:00 2001 From: AnotherCommander Date: Thu, 5 Jul 2018 14:57:48 +0200 Subject: [PATCH] Fixed erroneous behaviour when NaN was passed via script for pitch, roll and yaw. Closes #303. --- src/Core/Scripting/OOJSPlayerShip.m | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Core/Scripting/OOJSPlayerShip.m b/src/Core/Scripting/OOJSPlayerShip.m index e6459738..20452dab 100644 --- a/src/Core/Scripting/OOJSPlayerShip.m +++ b/src/Core/Scripting/OOJSPlayerShip.m @@ -789,7 +789,10 @@ static JSBool PlayerShipSetProperty(JSContext *context, JSObject *this, jsid pro case kPlayerShip_pitch: if (JS_ValueToNumber(context, *value, &fValue)) { - [player decrease_flight_pitch:[player flightPitch] + fValue]; + if (!isnan(fValue)) // guard against undefined + { + [player decrease_flight_pitch:[player flightPitch] + fValue]; + } return YES; } break; @@ -797,7 +800,10 @@ static JSBool PlayerShipSetProperty(JSContext *context, JSObject *this, jsid pro case kPlayerShip_roll: if (JS_ValueToNumber(context, *value, &fValue)) { - [player decrease_flight_roll:[player flightRoll] + fValue]; + if (!isnan(fValue)) // guard against undefined + { + [player decrease_flight_roll:[player flightRoll] + fValue]; + } return YES; } break; @@ -805,7 +811,10 @@ static JSBool PlayerShipSetProperty(JSContext *context, JSObject *this, jsid pro case kPlayerShip_yaw: if (JS_ValueToNumber(context, *value, &fValue)) { - [player decrease_flight_yaw:[player flightYaw] + fValue]; + if (!isnan(fValue)) // guard against undefined + { + [player decrease_flight_yaw:[player flightYaw] + fValue]; + } return YES; } break;