diff --git a/core/object/SCsub b/core/object/SCsub index dc116aeb19d4..92d6e53e5f28 100644 --- a/core/object/SCsub +++ b/core/object/SCsub @@ -9,4 +9,7 @@ env.CommandNoCache(["gdvirtual.gen.inc"], "make_virtuals.py", run_in_subprocess( env_object = env.Clone() +if env["tests"]: + env_object.Append(CPPDEFINES=["TESTS_ENABLED"]) + env_object.add_source_files(env.core_sources, "*.cpp") diff --git a/core/object/message_queue.cpp b/core/object/message_queue.cpp index dd7aba13844c..af29deaf8f3b 100644 --- a/core/object/message_queue.cpp +++ b/core/object/message_queue.cpp @@ -34,6 +34,7 @@ #include "core/core_string_names.h" #include "core/object/class_db.h" #include "core/object/script_language.h" +#include "thirdparty/doctest/doctest.h" #ifdef DEBUG_ENABLED #include "core/config/engine.h" @@ -322,8 +323,18 @@ Error CallQueue::flush() { UNLOCK_MUTEX; #ifdef DEBUG_ENABLED if (!message->callable.is_valid()) { + bool mute_error = false; // The editor would cause many of these. - if (!Engine::get_singleton()->is_editor_hint()) { + if (Engine::get_singleton()->is_editor_hint()) { + mute_error = true; + } +#ifdef TESTS_ENABLED + // Tests generally create objects and don't have to care about their fate when the queue is eventually flushed. + if (!mute_error && doctest::is_running_in_test) { + mute_error = true; + } +#endif + if (!mute_error) { ERR_PRINT("Trying to execute a deferred call/notification/set on a previously freed instance. Consider using queue_free() instead of free()."); } } else