diff --git a/Core/GDCore/Events/Serialization.cpp b/Core/GDCore/Events/Serialization.cpp index ec1a8bc2c6b8..c0c11dca10a6 100644 --- a/Core/GDCore/Events/Serialization.cpp +++ b/Core/GDCore/Events/Serialization.cpp @@ -359,21 +359,57 @@ void gd::EventsListSerialization::SerializeInstructionsTo( // Parameters SerializerElement& parameters = instruction.AddChild("parameters"); parameters.ConsiderAsArrayOf("parameter"); - for (std::size_t l = 0; l < list[k].GetParameters().size(); l++) { - if (l > 20000) { - // Even more than 100 parameters is suspicious but JS engines usually - // support up to 65k parameters. Stop at a fraction of that as we've seen - // in the wild some probable memory corruption that lead to serializing 2M - // parameters. - gd::LogError( - "Suspiciously very high number of parameters in an instruction. " - "Clamping at 20k. This might indicate a memory corruption."); - break; + // Remove this BooleanVariable logic when setDefaultValue is honored + if(list[k].GetType() == "BooleanVariable") { + bool b = false; + if(1 < list[k].GetParameters().size()) { + gd:String plainString = list[k].GetParameter(1).GetPlainString(); + if(plainString == "True" || plainString == "False") { + b = true; + } } - parameters.AddChild("parameter") - .SetValue(list[k].GetParameter(l).GetPlainString()); - } + if(b == true) { + for (std::size_t l = 0; l < list[k].GetParameters().size(); l++) { + if (l > 20000) { + // Even more than 100 parameters is suspicious but JS engines usually + // support up to 65k parameters. Stop at a fraction of that as we've seen + // in the wild some probable memory corruption that lead to serializing 2M + // parameters. + gd::LogError( + "Suspiciously very high number of parameters in an instruction. " + "Clamping at 20k. This might indicate a memory corruption."); + break; + } + + parameters.AddChild("parameter") + .SetValue(list[k].GetParameter(l).GetPlainString()); + } + } else { + if(0 < list[k].GetParameters().size()) { + parameters.AddChild("parameter").SetValue(list[k].GetParameter(0).GetPlainString()); + gd::String falseGDString = "False"; + parameters.AddChild("parameter").SetValue(falseGDString); + } + } + + } else { + for (std::size_t l = 0; l < list[k].GetParameters().size(); l++) { + if (l > 20000) { + // Even more than 100 parameters is suspicious but JS engines usually + // support up to 65k parameters. Stop at a fraction of that as we've seen + // in the wild some probable memory corruption that lead to serializing 2M + // parameters. + gd::LogError( + "Suspiciously very high number of parameters in an instruction. " + "Clamping at 20k. This might indicate a memory corruption."); + break; + } + + parameters.AddChild("parameter") + .SetValue(list[k].GetParameter(l).GetPlainString()); + } + } // Sub instructions if (!list[k].GetSubInstructions().empty()) { diff --git a/Core/GDCore/Extensions/Builtin/VariablesExtension.cpp b/Core/GDCore/Extensions/Builtin/VariablesExtension.cpp index 6c3c3f782011..207e754216c0 100644 --- a/Core/GDCore/Extensions/Builtin/VariablesExtension.cpp +++ b/Core/GDCore/Extensions/Builtin/VariablesExtension.cpp @@ -60,7 +60,7 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsVariablesExtension( "res/conditions/var.png") .AddParameter("variableOrPropertyOrParameter", _("Variable")) .AddParameter("trueorfalse", _("Check if the value is")) - .SetDefaultValue("true") + .SetDefaultValue("False") // This parameter allows to keep the operand expression // when the editor switch between variable instructions. .AddCodeOnlyParameter("trueorfalse", "");