From 0087a4a5a447a6373a3e9f04a9daeb252329cae6 Mon Sep 17 00:00:00 2001 From: past-due <30942300+past-due@users.noreply.github.com> Date: Sun, 7 Jul 2024 13:48:18 -0400 Subject: [PATCH] wzapi: Additional checks for nan --- src/wzapi.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/wzapi.cpp b/src/wzapi.cpp index 747ed751756..e0cc2512d64 100644 --- a/src/wzapi.cpp +++ b/src/wzapi.cpp @@ -411,6 +411,7 @@ bool wzapi::setAssemblyPoint(WZAPI_PARAMS(STRUCTURE *psStruct, int x, int y)) //-- bool wzapi::setSunPosition(WZAPI_PARAMS(float x, float y, float z)) { + SCRIPT_ASSERT(false, context, !std::isnan(x) && !std::isnan(y) && !std::isnan(z), "Inputs must not be nan"); setTheSun(Vector3f(x, y, z)); return true; } @@ -421,6 +422,10 @@ bool wzapi::setSunPosition(WZAPI_PARAMS(float x, float y, float z)) //-- bool wzapi::setSunIntensity(WZAPI_PARAMS(float ambient_r, float ambient_g, float ambient_b, float diffuse_r, float diffuse_g, float diffuse_b, float specular_r, float specular_g, float specular_b)) { + SCRIPT_ASSERT(false, context, !std::isnan(ambient_r) && !std::isnan(ambient_g) && !std::isnan(ambient_b), "ambient inputs must not be nan"); + SCRIPT_ASSERT(false, context, !std::isnan(diffuse_r) && !std::isnan(diffuse_g) && !std::isnan(diffuse_b), "diffuse inputs must not be nan"); + SCRIPT_ASSERT(false, context, !std::isnan(specular_r) && !std::isnan(specular_g) && !std::isnan(specular_b), "specular inputs must not be nan"); + float ambient[4]; float diffuse[4]; float specular[4]; @@ -470,6 +475,9 @@ bool wzapi::setWeather(WZAPI_PARAMS(int weatherType)) //-- bool wzapi::setSky(WZAPI_PARAMS(std::string textureFilename, float windSpeed, float scale)) { + SCRIPT_ASSERT(false, context, !std::isnan(windSpeed), "windSpeed must not be nan"); + SCRIPT_ASSERT(false, context, !std::isnan(scale), "scale must not be nan"); + setSkyBox(textureFilename.c_str(), windSpeed, scale); return true; // TODO: modify setSkyBox to return bool, success / failure } @@ -480,6 +488,9 @@ bool wzapi::setSky(WZAPI_PARAMS(std::string textureFilename, float windSpeed, fl //-- bool wzapi::cameraSlide(WZAPI_PARAMS(float x, float y)) { + SCRIPT_ASSERT(false, context, !std::isnan(x), "x must not be nan"); + SCRIPT_ASSERT(false, context, !std::isnan(y), "y must not be nan"); + requestRadarTrack(static_cast(x), static_cast(y)); return true; } @@ -490,6 +501,9 @@ bool wzapi::cameraSlide(WZAPI_PARAMS(float x, float y)) //-- bool wzapi::cameraZoom(WZAPI_PARAMS(float viewDistance, float speed)) { + SCRIPT_ASSERT(false, context, !std::isnan(viewDistance), "viewDistance must not be nan"); + SCRIPT_ASSERT(false, context, !std::isnan(speed), "speed must not be nan"); + animateToViewDistance(viewDistance, speed); return true; }