Add checks against leftover children and orphan nodes

This commit is contained in:
JeremyStar™ 2024-03-31 03:12:14 +02:00
parent 7e050aa6ab
commit 82cf251ece
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D

View file

@ -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.")