From ea85ff0dc2a04e695d396f62ce5949f4e04254e4 Mon Sep 17 00:00:00 2001 From: Ignacio Etcheverry Date: Thu, 10 Jan 2019 00:26:00 +0100 Subject: 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). --- modules/gdscript/gdscript.cpp | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'modules/gdscript/gdscript.cpp') diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 538249c8e2..3904ec6389 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -475,20 +475,15 @@ bool GDScript::_update_exports() { _signals[c->_signals[i].name] = c->_signals[i].arguments; } } else { - for (Set::Element *E = placeholders.front(); E; E = E->next()) { - E->get()->set_build_failed(true); - } - return false; - } - } else { - if (!valid) { - for (Set::Element *E = placeholders.front(); E; E = E->next()) { - E->get()->set_build_failed(true); - } + placeholder_fallback_enabled = true; return false; } + } else if (!valid || placeholder_fallback_enabled) { + return false; } + placeholder_fallback_enabled = false; + if (base_cache.is_valid()) { if (base_cache->_update_exports()) { changed = true; @@ -503,7 +498,6 @@ bool GDScript::_update_exports() { _update_exports_values(values, propnames); for (Set::Element *E = placeholders.front(); E; E = E->next()) { - E->get()->set_build_failed(false); E->get()->update(propnames, values); } } @@ -907,6 +901,7 @@ GDScript::GDScript() : tool = false; #ifdef TOOLS_ENABLED source_changed_cache = false; + placeholder_fallback_enabled = false; #endif #ifdef DEBUG_ENABLED @@ -1675,6 +1670,8 @@ void GDScriptLanguage::reload_tool_script(const Ref