mirror of
https://github.com/godotengine/godot.git
synced 2025-10-21 00:43:46 +00:00
Complain if casting a freed object in a debug session
The idea is to give the user a chance to realize a mistake that will cause a crash in a release build (or with no debugger attached).
This commit is contained in:
parent
504f47eaec
commit
123d3ef935
3 changed files with 33 additions and 0 deletions
|
@ -846,6 +846,10 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
|
|||
*dst = Variant::construct(to_type, (const Variant **)&src, 1, err);
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
if (src->get_type() == Variant::OBJECT && !src->is_ref() && ObjectDB::get_instance(src->get_object_instance_id()) == nullptr) {
|
||||
err_text = "Trying to cast a deleted object.";
|
||||
OPCODE_BREAK;
|
||||
}
|
||||
if (err.error != Variant::CallError::CALL_OK) {
|
||||
err_text = "Invalid cast: could not convert value to '" + Variant::get_type_name(to_type) + "'.";
|
||||
OPCODE_BREAK;
|
||||
|
@ -866,6 +870,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->is_ref() && ObjectDB::get_instance(src->get_object_instance_id()) == nullptr) {
|
||||
err_text = "Trying to cast a deleted 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;
|
||||
|
@ -894,6 +902,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->is_ref() && ObjectDB::get_instance(src->get_object_instance_id()) == nullptr) {
|
||||
err_text = "Trying to cast a deleted 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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue