diff options
author | Bojidar Marinov <bojidar.marinov.bg@gmail.com> | 2019-06-29 15:51:33 +0300 |
---|---|---|
committer | Bojidar Marinov <bojidar.marinov.bg@gmail.com> | 2019-06-29 15:51:33 +0300 |
commit | 55234d62b079fd6a18b9f0dafaf4af296becfe20 (patch) | |
tree | fadf532167e585ffcb640046dca5e4457059d5b3 | |
parent | ae70eca5afbf8a6b1d5c11cec96c5746845391bc (diff) |
Remove bogus nulls from generated default values
Also, fix crash in PluginScript destructor.
-rw-r--r-- | core/class_db.cpp | 5 | ||||
-rw-r--r-- | core/class_db.h | 2 | ||||
-rw-r--r-- | editor/doc/doc_data.cpp | 19 | ||||
-rw-r--r-- | modules/gdnative/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 34bc83c89a..9fe9b23c68 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<String> *p HashMap<StringName, HashMap<StringName, Variant> > ClassDB::default_values; Set<StringName> 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 8adbc9ba98..237ae9b806 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<StringName> *p_enums, bool p_no_inheritance = false); static void get_enum_constants(const StringName &p_class, const StringName &p_enum, List<StringName> *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 468819151f..6ee07d3661 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<StringName> inheriting_classes; ClassDB::get_direct_inheriters_from_class(name, &inheriting_classes); for (List<StringName>::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 310fa7000e..3ecb29404a 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 } |