From 1100f0f1ebc9408a529604abfbf5d2d4b87c0a7b Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Wed, 30 Oct 2019 15:16:34 +0900 Subject: [PATCH] Allow parsing integer number value as double(For example, glTF-Sample-Models/2.0/Cameras/glTF has `zfar` number property with integer value, which trigerred a parsing failure). --- tiny_gltf.h | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index 96d8ada..23b16c9 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -2567,23 +2567,16 @@ bool GetInt(const json &o, int &val) { #endif } -bool GetDouble(const json &o, double &val) { #ifdef TINYGLTF_USE_RAPIDJSON +bool GetDouble(const json &o, double &val) { if (o.IsDouble()) { val = o.GetDouble(); return true; } return false; -#else - if (o.type() == json::value_t::number_float) { - val = static_cast(o.get()); - return true; - } - - return false; -#endif } +#endif bool GetNumber(const json &o, double &val) { #ifdef TINYGLTF_USE_RAPIDJSON @@ -2961,10 +2954,10 @@ static bool ParseNumberProperty(double *ret, std::string *err, const json &o, return false; } - double doubleValue; - bool isDouble = GetDouble(GetValue(it), doubleValue); + double numberValue; + bool isNumber = GetNumber(GetValue(it), numberValue); - if (!isDouble) { + if (!isNumber) { if (required) { if (err) { (*err) += "'" + property + "' property is not a number type.\n"; @@ -2974,7 +2967,7 @@ static bool ParseNumberProperty(double *ret, std::string *err, const json &o, } if (ret) { - (*ret) = doubleValue; + (*ret) = numberValue; } return true;