diff options
| author | David Snopek <dsnopek@gmail.com> | 2024-05-07 12:54:35 -0500 |
|---|---|---|
| committer | David Snopek <dsnopek@gmail.com> | 2024-05-10 19:51:31 -0500 |
| commit | 88df025aa0ab92ed176f91dd835c004fa26f0ed0 (patch) | |
| tree | 61c4a3c454986d3723a095ff46f91f0f3eecafb0 /src/core | |
| parent | 85172dad1bd3cfed8cf8b4c2826f34cfe211af05 (diff) | |
| download | redot-cpp-88df025aa0ab92ed176f91dd835c004fa26f0ed0.tar.gz | |
Clean up instance bindings for engine singletons to prevent crash
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/class_db.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/core/class_db.cpp b/src/core/class_db.cpp index acead8b..d9a8bf9 100644 --- a/src/core/class_db.cpp +++ b/src/core/class_db.cpp @@ -43,6 +43,8 @@ namespace godot { std::unordered_map<StringName, ClassDB::ClassInfo> ClassDB::classes; std::unordered_map<StringName, const GDExtensionInstanceBindingCallbacks *> ClassDB::instance_binding_callbacks; std::vector<StringName> ClassDB::class_register_order; +std::unordered_map<StringName, Object *> ClassDB::engine_singletons; +std::mutex ClassDB::engine_singletons_mutex; GDExtensionInitializationLevel ClassDB::current_level = GDEXTENSION_INITIALIZATION_CORE; MethodDefinition D_METHOD(StringName p_name) { @@ -419,6 +421,22 @@ void ClassDB::deinitialize(GDExtensionInitializationLevel p_level) { }); class_register_order.erase(it, class_register_order.end()); } + + if (p_level == GDEXTENSION_INITIALIZATION_CORE) { + // Make a new list of the singleton objects, since freeing the instance bindings will lead to + // elements getting removed from engine_singletons. + std::vector<Object *> singleton_objects; + { + std::lock_guard<std::mutex> lock(engine_singletons_mutex); + singleton_objects.reserve(engine_singletons.size()); + for (const std::pair<StringName, Object *> &pair : engine_singletons) { + singleton_objects.push_back(pair.second); + } + } + for (std::vector<Object *>::iterator i = singleton_objects.begin(); i != singleton_objects.end(); i++) { + internal::gdextension_interface_object_free_instance_binding((*i)->_owner, internal::token); + } + } } } // namespace godot |
