From 3718f8f5925bad0662d9ae84192d094b5da4d644 Mon Sep 17 00:00:00 2001 From: George Marques Date: Thu, 9 Jan 2020 13:59:33 -0300 Subject: GDScript: Validate object instance on `is` operation Avoids crashes on debug mode. Instead it now breaks the execution and show the error in-editor. Will still crash on release. Also add a similar check to Marshalls to ensure the debugger doesn't crash when trying to serialize the invalid instance. --- modules/gdscript/gdscript_function.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'modules/gdscript/gdscript_function.cpp') diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp index a01a7397fe..eef39da8b5 100644 --- a/modules/gdscript/gdscript_function.cpp +++ b/modules/gdscript/gdscript_function.cpp @@ -500,6 +500,13 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a Object *obj_A = *a; Object *obj_B = *b; +#ifdef DEBUG_ENABLED + if (!ObjectDB::instance_validate(obj_A)) { + err_text = "Left operand of 'is' was already freed."; + OPCODE_BREAK; + } +#endif // DEBUG_ENABLED + GDScript *scr_B = Object::cast_to(obj_B); if (scr_B) { -- cgit v1.2.3