From ffdb3cccd2a80417475826151d93529893809850 Mon Sep 17 00:00:00 2001 From: George Marques Date: Mon, 24 May 2021 14:17:20 -0300 Subject: GDScript: Fix error handler for tests This changes the error message to be more clear on the output files and also fixes an issue with the relative path of the offending file that was not trimmed correctly. --- modules/gdscript/tests/gdscript_test_runner.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/gdscript/tests/gdscript_test_runner.cpp b/modules/gdscript/tests/gdscript_test_runner.cpp index 76ae43e792..e20e427597 100644 --- a/modules/gdscript/tests/gdscript_test_runner.cpp +++ b/modules/gdscript/tests/gdscript_test_runner.cpp @@ -257,6 +257,7 @@ bool GDScriptTestRunner::make_tests() { ERR_FAIL_COND_V_MSG(err != OK, false, "Could not open specified test directory."); + source_dir = dir->get_current_dir() + "/"; // Make it absolute path. return make_tests_for_dir(dir->get_current_dir()); } @@ -361,11 +362,9 @@ void GDScriptTest::error_handler(void *p_this, const char *p_function, const cha break; } - builder.append("\n>> "); - builder.append(p_function); - builder.append("\n>> "); + builder.append("\n>> on function: "); builder.append(p_function); - builder.append("\n>> "); + builder.append("()\n>> "); builder.append(String(p_file).trim_prefix(self->base_dir)); builder.append("\n>> "); builder.append(itos(p_line)); -- cgit v1.2.3 From ea44744e2daf512ac97ba7176d1e65d77b4f8042 Mon Sep 17 00:00:00 2001 From: George Marques Date: Mon, 24 May 2021 14:18:39 -0300 Subject: Make Callable not crash on call when the object has been freed Also add a GDScript test for this case. --- core/variant/callable.cpp | 9 +++++++++ .../scripts/runtime/errors/callable_call_after_free_object.gd | 5 +++++ .../scripts/runtime/errors/callable_call_after_free_object.out | 6 ++++++ 3 files changed, 20 insertions(+) create mode 100644 modules/gdscript/tests/scripts/runtime/errors/callable_call_after_free_object.gd create mode 100644 modules/gdscript/tests/scripts/runtime/errors/callable_call_after_free_object.out diff --git a/core/variant/callable.cpp b/core/variant/callable.cpp index e06b3e07ef..5c87042f6b 100644 --- a/core/variant/callable.cpp +++ b/core/variant/callable.cpp @@ -50,6 +50,15 @@ void Callable::call(const Variant **p_arguments, int p_argcount, Variant &r_retu custom->call(p_arguments, p_argcount, r_return_value, r_call_error); } else { Object *obj = ObjectDB::get_instance(ObjectID(object)); +#ifdef DEBUG_ENABLED + if (!obj) { + r_call_error.error = CallError::CALL_ERROR_INSTANCE_IS_NULL; + r_call_error.argument = 0; + r_call_error.expected = 0; + r_return_value = Variant(); + return; + } +#endif r_return_value = obj->call(method, p_arguments, p_argcount, r_call_error); } } diff --git a/modules/gdscript/tests/scripts/runtime/errors/callable_call_after_free_object.gd b/modules/gdscript/tests/scripts/runtime/errors/callable_call_after_free_object.gd new file mode 100644 index 0000000000..10780b5379 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/callable_call_after_free_object.gd @@ -0,0 +1,5 @@ +func test(): + var node := Node.new() + var inside_tree = node.is_inside_tree + node.free() + inside_tree.call() diff --git a/modules/gdscript/tests/scripts/runtime/errors/callable_call_after_free_object.out b/modules/gdscript/tests/scripts/runtime/errors/callable_call_after_free_object.out new file mode 100644 index 0000000000..e585c374e2 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/callable_call_after_free_object.out @@ -0,0 +1,6 @@ +GDTEST_RUNTIME_ERROR +>> SCRIPT ERROR +>> on function: test() +>> runtime/errors/callable_call_after_free_object.gd +>> 5 +>> Attempt to call function 'null::is_inside_tree (Callable)' on a null instance. -- cgit v1.2.3