From 82cf251ecee89f3f2a575b1b322c1df48ea42aaf Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Sun, 31 Mar 2024 03:12:14 +0200 Subject: [PATCH] Add checks against leftover children and orphan nodes --- addons/besseretests/src/runtimescene.gd | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/addons/besseretests/src/runtimescene.gd b/addons/besseretests/src/runtimescene.gd index cdc99bc..9a5faa4 100644 --- a/addons/besseretests/src/runtimescene.gd +++ b/addons/besseretests/src/runtimescene.gd @@ -2,8 +2,8 @@ extends Control # Configuration for the configuration var config: Node = Node.new() -var config_path: String = "res://addons/besseretests_config.gd" -var config_keys: Dictionary = {"test_directory": TYPE_STRING} +const config_path: String = "res://addons/besseretests_config.gd" +const config_keys: Dictionary = { "test_directory": TYPE_STRING } # Configuration var config_test_directory: String = "res://tests" @@ -157,7 +157,16 @@ func lsanitize(message: String) -> String: # Terminates the engine func terminate(exit_code: int = 0) -> void: config.queue_free() + check_children() + check_orphan_nodes() linfo("Shutting down...") await get_tree().create_timer(0.25).timeout queue_free() get_tree().quit(exit_code) + +# Checks +func check_children() -> void: + if get_tree().root.get_child_count() != 1: lwarn("There are still '" + str(get_tree().root.get_child_count()-1) + "' children active in the scene tree. Please make sure to call 'remove_child' on them in your tests.") + +func check_orphan_nodes() -> void: + if Performance.get_monitor(Performance.OBJECT_ORPHAN_NODE_COUNT) != 4: lwarn("There are still '" + str(Performance.get_monitor(Performance.OBJECT_ORPHAN_NODE_COUNT)) + "' orphan nodes loaded. Please make sure to call 'queue_free' or 'free' on them in your tests.")