Validate instances of objects before trying to check their type in GDScript

Fixes #27582
This commit is contained in:
Bojidar Marinov 2020-01-16 15:53:34 +02:00
parent 3af0400a32
commit dc4455d819
No known key found for this signature in database
GPG key ID: 4D546A8F1E091856

View file

@ -76,14 +76,17 @@ struct GDScriptDataType {
if (p_variant.get_type() != Variant::OBJECT) { if (p_variant.get_type() != Variant::OBJECT) {
return false; return false;
} }
Object *obj = p_variant.operator Object *(); Object *obj = p_variant.operator Object *();
if (obj) { if (!obj || !ObjectDB::instance_validate(obj)) {
if (!ClassDB::is_parent_class(obj->get_class_name(), native_type)) { return false;
// Try with underscore prefix }
StringName underscore_native_type = "_" + native_type;
if (!ClassDB::is_parent_class(obj->get_class_name(), underscore_native_type)) { if (!ClassDB::is_parent_class(obj->get_class_name(), native_type)) {
return false; // Try with underscore prefix
} StringName underscore_native_type = "_" + native_type;
if (!ClassDB::is_parent_class(obj->get_class_name(), underscore_native_type)) {
return false;
} }
} }
return true; return true;
@ -96,7 +99,12 @@ struct GDScriptDataType {
if (p_variant.get_type() != Variant::OBJECT) { if (p_variant.get_type() != Variant::OBJECT) {
return false; return false;
} }
Object *obj = p_variant.operator Object *(); Object *obj = p_variant.operator Object *();
if (!obj || !ObjectDB::instance_validate(obj)) {
return false;
}
Ref<Script> base = obj && obj->get_script_instance() ? obj->get_script_instance()->get_script() : NULL; Ref<Script> base = obj && obj->get_script_instance() ? obj->get_script_instance()->get_script() : NULL;
bool valid = false; bool valid = false;
while (base.is_valid()) { while (base.is_valid()) {