Remove bogus nulls from generated default values

Also, fix crash in PluginScript destructor.
This commit is contained in:
Bojidar Marinov 2019-06-29 15:51:33 +03:00
parent ae70eca5af
commit 55234d62b0
No known key found for this signature in database
GPG key ID: 4B0FD31949AD430D
4 changed files with 30 additions and 12 deletions

View file

@ -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];
}

View file

@ -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);

View file

@ -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();
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);

View file

@ -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() {
if (_desc && _data) {
_desc->finish(_data);
}
#ifdef DEBUG_ENABLED
if (_language) {
_language->lock();
_language->_script_list.remove(&_script_list);
_language->unlock();
}
#endif
}