Merge pull request #35201 from bojidar-bg/27582-gdfunction-validate-instance

Validate instances of objects before trying to check their type in GDScript
This commit is contained in:
Rémi Verschelde 2020-01-16 15:57:44 +01:00 committed by GitHub
commit f2aa99a8e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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