From ea85ff0dc2a04e695d396f62ce5949f4e04254e4 Mon Sep 17 00:00:00 2001 From: Ignacio Etcheverry Date: Thu, 10 Jan 2019 00:26:00 +0100 Subject: [PATCH] Fix properties being lost when reloading placeholder GDScript instance During reloading in `GDScriptLanguage::reload_all_scripts` a placeholder instance that must remain so is replaced with a new placeholder instance. The state is then restored by calling `ScriptInstance::set` for each property. This does not work if the script is missing the properties due to build/parse failing. The fix for such cases is to call `placeholder_set_fallback` instead of `set` on the script instance. I took this chance to move the `build_failed` flag from `PlaceHolderScriptInstance` to `Script`. That improves the code a lot. I also renamed it to `placeholder_fallback_enabled` which is a much better name (`build_failed` could lead to misunderstandings). --- core/script_language.cpp | 19 ++++++++--------- core/script_language.h | 11 ++++------ modules/gdscript/gdscript.cpp | 37 ++++++++++++++++++++-------------- modules/gdscript/gdscript.h | 5 +++++ modules/mono/csharp_script.cpp | 14 ++++++------- modules/mono/csharp_script.h | 5 +++++ 6 files changed, 51 insertions(+), 40 deletions(-) diff --git a/core/script_language.cpp b/core/script_language.cpp index 496521486e7..120a87d078f 100644 --- a/core/script_language.cpp +++ b/core/script_language.cpp @@ -376,7 +376,7 @@ ScriptDebugger::ScriptDebugger() { bool PlaceHolderScriptInstance::set(const StringName &p_name, const Variant &p_value) { - if (build_failed) + if (script->is_placeholder_fallback_enabled()) return false; if (values.has(p_name)) { @@ -407,7 +407,7 @@ bool PlaceHolderScriptInstance::get(const StringName &p_name, Variant &r_ret) co return true; } - if (!build_failed) { + if (!script->is_placeholder_fallback_enabled()) { Variant defval; if (script->get_property_default_value(p_name, defval)) { r_ret = defval; @@ -420,7 +420,7 @@ bool PlaceHolderScriptInstance::get(const StringName &p_name, Variant &r_ret) co void PlaceHolderScriptInstance::get_property_list(List *p_properties) const { - if (build_failed) { + if (script->is_placeholder_fallback_enabled()) { for (const List::Element *E = properties.front(); E; E = E->next()) { p_properties->push_back(E->get()); } @@ -450,7 +450,7 @@ Variant::Type PlaceHolderScriptInstance::get_property_type(const StringName &p_n void PlaceHolderScriptInstance::get_method_list(List *p_list) const { - if (build_failed) + if (script->is_placeholder_fallback_enabled()) return; if (script.is_valid()) { @@ -459,7 +459,7 @@ void PlaceHolderScriptInstance::get_method_list(List *p_list) const } bool PlaceHolderScriptInstance::has_method(const StringName &p_method) const { - if (build_failed) + if (script->is_placeholder_fallback_enabled()) return false; if (script.is_valid()) { @@ -470,8 +470,6 @@ bool PlaceHolderScriptInstance::has_method(const StringName &p_method) const { void PlaceHolderScriptInstance::update(const List &p_properties, const Map &p_values) { - build_failed = false; - Set new_values; for (const List::Element *E = p_properties.front(); E; E = E->next()) { @@ -517,7 +515,7 @@ void PlaceHolderScriptInstance::update(const List &p_properties, c void PlaceHolderScriptInstance::property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid) { - if (build_failed) { + if (script->is_placeholder_fallback_enabled()) { Map::Element *E = values.find(p_name); if (E) { @@ -544,7 +542,7 @@ void PlaceHolderScriptInstance::property_set_fallback(const StringName &p_name, Variant PlaceHolderScriptInstance::property_get_fallback(const StringName &p_name, bool *r_valid) { - if (build_failed) { + if (script->is_placeholder_fallback_enabled()) { const Map::Element *E = values.find(p_name); if (E) { @@ -563,8 +561,7 @@ Variant PlaceHolderScriptInstance::property_get_fallback(const StringName &p_nam PlaceHolderScriptInstance::PlaceHolderScriptInstance(ScriptLanguage *p_language, Ref