Read and write exported infs/nans correctly (#35388)

This commit is contained in:
sumit0190 2020-02-09 00:46:13 -05:00
parent de932a5285
commit c4dbd8a744
1 changed files with 8 additions and 2 deletions

View File

@ -512,6 +512,10 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
value = false; value = false;
else if (id == "null" || id == "nil") else if (id == "null" || id == "nil")
value = Variant(); value = Variant();
else if (id == "inf")
value = Math_INF;
else if (id == "nan")
value = Math_NAN;
else if (id == "Vector2") { else if (id == "Vector2") {
Vector<float> args; Vector<float> args;
@ -1586,8 +1590,10 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
case Variant::REAL: { case Variant::REAL: {
String s = rtosfix(p_variant.operator real_t()); String s = rtosfix(p_variant.operator real_t());
if (s.find(".") == -1 && s.find("e") == -1) if (s != "inf" && s != "nan") {
s += ".0"; if (s.find(".") == -1 && s.find("e") == -1)
s += ".0";
}
p_store_string_func(p_store_string_ud, s); p_store_string_func(p_store_string_ud, s);
} break; } break;
case Variant::STRING: { case Variant::STRING: {