Auto-release static GDTypes at exit.

This fixes "unclaimed StringName" warnings and improves engine shutdown correctness.
This commit is contained in:
Lukas Tenbrink
2026-01-09 13:46:28 +01:00
parent 64bc9a25a3
commit 17ef5afa6c
3 changed files with 17 additions and 1 deletions

View File

@@ -2420,6 +2420,7 @@ void ClassDB::cleanup_defaults() {
default_values_cached.clear();
}
LocalVector<GDType **> ClassDB::gdtype_autorelease_pool;
void ClassDB::cleanup() {
//OBJTYPE_LOCK; hah not here
@@ -2440,6 +2441,15 @@ void ClassDB::cleanup() {
resource_base_extensions.clear();
compat_classes.clear();
native_structs.clear();
for (GDType **type : gdtype_autorelease_pool) {
if (!type) {
WARN_PRINT("GDType in autorelease pool was cleaned up before being auto-released. Ignoring.");
}
memdelete(*type);
*type = nullptr;
}
gdtype_autorelease_pool.clear();
}
// Array to use in optional parameters on methods and the DEFVAL_ARRAY macro.

View File

@@ -234,6 +234,10 @@ public:
static Array default_array_arg;
static bool is_default_array_arg(const Array &p_array);
// Types added here will be automatically cleaned up on engine shutdown.
// Only add types that aren't cleaned up in another way.
static LocalVector<GDType **> gdtype_autorelease_pool;
private:
// Non-locking variants of get_parent_class and is_parent_class.
static StringName _get_parent_class(const StringName &p_class);

View File

@@ -2383,8 +2383,10 @@ void Object::assign_type_static(GDType **type_ptr, const char *p_name, const GDT
// Assigned while we were waiting.
return;
}
type = memnew(GDType(super_type, StringName(p_name, true)));
type = memnew(GDType(super_type, StringName(p_name)));
*type_ptr = type;
ClassDB::gdtype_autorelease_pool.push_back(type_ptr);
}
Object::~Object() {