From 55234d62b079fd6a18b9f0dafaf4af296becfe20 Mon Sep 17 00:00:00 2001 From: Bojidar Marinov Date: Sat, 29 Jun 2019 15:51:33 +0300 Subject: [PATCH] Remove bogus nulls from generated default values Also, fix crash in PluginScript destructor. --- core/class_db.cpp | 5 ++++- core/class_db.h | 2 +- editor/doc/doc_data.cpp | 19 +++++++++++++------ .../pluginscript/pluginscript_script.cpp | 16 ++++++++++++---- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/core/class_db.cpp b/core/class_db.cpp index 34bc83c89af..9fe9b23c685 100644 --- a/core/class_db.cpp +++ b/core/class_db.cpp @@ -1397,7 +1397,7 @@ void ClassDB::get_extensions_for_type(const StringName &p_class, List *p HashMap > ClassDB::default_values; Set ClassDB::default_values_cached; -Variant ClassDB::class_get_default_property_value(const StringName &p_class, const StringName &p_property) { +Variant ClassDB::class_get_default_property_value(const StringName &p_class, const StringName &p_property, bool *r_valid) { if (!default_values_cached.has(p_class)) { @@ -1439,13 +1439,16 @@ Variant ClassDB::class_get_default_property_value(const StringName &p_class, con } if (!default_values.has(p_class)) { + if (r_valid != NULL) *r_valid = false; return Variant(); } if (!default_values[p_class].has(p_property)) { + if (r_valid != NULL) *r_valid = false; return Variant(); } + if (r_valid != NULL) *r_valid = true; return default_values[p_class][p_property]; } diff --git a/core/class_db.h b/core/class_db.h index 8adbc9ba982..237ae9b8062 100644 --- a/core/class_db.h +++ b/core/class_db.h @@ -357,7 +357,7 @@ public: static void get_enum_list(const StringName &p_class, List *p_enums, bool p_no_inheritance = false); static void get_enum_constants(const StringName &p_class, const StringName &p_enum, List *p_constants, bool p_no_inheritance = false); - static Variant class_get_default_property_value(const StringName &p_class, const StringName &p_property); + static Variant class_get_default_property_value(const StringName &p_class, const StringName &p_property, bool *r_valid = NULL); static StringName get_category(const StringName &p_node); diff --git a/editor/doc/doc_data.cpp b/editor/doc/doc_data.cpp index 468819151f6..6ee07d36615 100644 --- a/editor/doc/doc_data.cpp +++ b/editor/doc/doc_data.cpp @@ -248,21 +248,28 @@ void DocData::generate(bool p_basic_types) { prop.setter = setter; prop.getter = getter; - if (ClassDB::can_instance(name)) { // Cannot get default value of classes that can't be instanced - Variant default_value = ClassDB::class_get_default_property_value(name, E->get().name); - prop.default_value = default_value.get_construct_string(); + Variant default_value = Variant(); + bool default_value_valid = false; + + if (ClassDB::can_instance(name)) { + default_value = ClassDB::class_get_default_property_value(name, E->get().name, &default_value_valid); } else { + // Cannot get default value of classes that can't be instanced List inheriting_classes; ClassDB::get_direct_inheriters_from_class(name, &inheriting_classes); for (List::Element *E2 = inheriting_classes.front(); E2; E2 = E2->next()) { if (ClassDB::can_instance(E2->get())) { - Variant default_value = ClassDB::class_get_default_property_value(E2->get(), E->get().name); - prop.default_value = default_value.get_construct_string(); - break; + default_value = ClassDB::class_get_default_property_value(E2->get(), E->get().name, &default_value_valid); + if (default_value_valid) + break; } } } + if (default_value_valid) { + prop.default_value = default_value.get_construct_string(); + } + bool found_type = false; if (getter != StringName()) { MethodBind *mb = ClassDB::get_method(name, getter); diff --git a/modules/gdnative/pluginscript/pluginscript_script.cpp b/modules/gdnative/pluginscript/pluginscript_script.cpp index 310fa7000ee..3ecb29404a2 100644 --- a/modules/gdnative/pluginscript/pluginscript_script.cpp +++ b/modules/gdnative/pluginscript/pluginscript_script.cpp @@ -229,6 +229,8 @@ void PluginScript::set_source_code(const String &p_code) { } Error PluginScript::reload(bool p_keep_state) { + ERR_FAIL_COND_V(!_language, ERR_UNCONFIGURED); + _language->lock(); ERR_FAIL_COND_V(!p_keep_state && _instances.size(), ERR_ALREADY_IN_USE); _language->unlock(); @@ -473,6 +475,8 @@ MultiplayerAPI::RPCMode PluginScript::get_rset_mode(const StringName &p_variable PluginScript::PluginScript() : _data(NULL), + _desc(NULL), + _language(NULL), _tool(false), _valid(false), _script_list(this) { @@ -490,11 +494,15 @@ void PluginScript::init(PluginScriptLanguage *language) { } PluginScript::~PluginScript() { - _desc->finish(_data); + if (_desc && _data) { + _desc->finish(_data); + } #ifdef DEBUG_ENABLED - _language->lock(); - _language->_script_list.remove(&_script_list); - _language->unlock(); + if (_language) { + _language->lock(); + _language->_script_list.remove(&_script_list); + _language->unlock(); + } #endif }