Fix GDScript::_get_gdscript_from_variant() crash

The crash would happen, theoretically, when getting the type of a invalid
variant.
This commit is contained in:
Adam Scott 2022-12-15 11:53:38 -05:00
parent d99ea32999
commit 3684fd249e

View file

@ -1288,15 +1288,10 @@ String GDScript::_get_gdscript_reference_class_name(const GDScript *p_gdscript)
}
GDScript *GDScript::_get_gdscript_from_variant(const Variant &p_variant) {
Variant::Type type = p_variant.get_type();
if (type != Variant::Type::OBJECT)
return nullptr;
Object *obj = p_variant;
if (obj == nullptr) {
if (obj == nullptr || obj->get_instance_id().is_null()) {
return nullptr;
}
return Object::cast_to<GDScript>(obj);
}