diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-09-14 21:48:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-14 21:48:10 +0200 |
commit | 1c7aec9d9cc15c338e4dfa5228825901efadb477 (patch) | |
tree | 7e6961f2ad56d4464503c047a86c71ab368c2a90 | |
parent | c5a979eba54fea9b68b76012c89b9095129473a8 (diff) | |
parent | ddc7d7ee66dccbec60d1c9108f8b2225c6d9adcc (diff) |
Merge pull request #51094 from RandomShaper/error_cast_freed_object
Complain if casting a freed object in a debug session
-rw-r--r-- | modules/gdscript/gdscript_vm.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/modules/gdscript/gdscript_vm.cpp b/modules/gdscript/gdscript_vm.cpp index 64fd7eca8a..bf21c8510a 100644 --- a/modules/gdscript/gdscript_vm.cpp +++ b/modules/gdscript/gdscript_vm.cpp @@ -1232,6 +1232,13 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a GD_ERR_BREAK(to_type < 0 || to_type >= Variant::VARIANT_MAX); +#ifdef DEBUG_ENABLED + if (src->get_type() == Variant::OBJECT && !src->operator ObjectID().is_ref_counted() && ObjectDB::get_instance(src->operator ObjectID()) == nullptr) { + err_text = "Trying to cast a freed object."; + OPCODE_BREAK; + } +#endif + Callable::CallError err; Variant::construct(to_type, *dst, (const Variant **)&src, 1, err); @@ -1256,6 +1263,10 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a GD_ERR_BREAK(!nc); #ifdef DEBUG_ENABLED + if (src->get_type() == Variant::OBJECT && !src->operator ObjectID().is_ref_counted() && ObjectDB::get_instance(src->operator ObjectID()) == nullptr) { + err_text = "Trying to cast a freed object."; + OPCODE_BREAK; + } if (src->get_type() != Variant::OBJECT && src->get_type() != Variant::NIL) { err_text = "Invalid cast: can't convert a non-object value to an object type."; OPCODE_BREAK; @@ -1284,6 +1295,10 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a GD_ERR_BREAK(!base_type); #ifdef DEBUG_ENABLED + if (src->get_type() == Variant::OBJECT && !src->operator ObjectID().is_ref_counted() && ObjectDB::get_instance(src->operator ObjectID()) == nullptr) { + err_text = "Trying to cast a freed object."; + OPCODE_BREAK; + } if (src->get_type() != Variant::OBJECT && src->get_type() != Variant::NIL) { err_text = "Trying to assign a non-object value to a variable of type '" + base_type->get_path().get_file() + "'."; OPCODE_BREAK; |