Merge pull request #1047 from Kehom/master

Unregister custom classes in reverse registration order
pull/1150/head
David Snopek 2023-06-20 08:24:56 -05:00 committed by GitHub
commit 2377f7ec75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -105,6 +105,8 @@ private:
// This may only contain custom classes, not Godot classes // This may only contain custom classes, not Godot classes
static std::unordered_map<StringName, ClassInfo> classes; static std::unordered_map<StringName, ClassInfo> classes;
static std::unordered_map<StringName, const GDExtensionInstanceBindingCallbacks *> instance_binding_callbacks; static std::unordered_map<StringName, const GDExtensionInstanceBindingCallbacks *> instance_binding_callbacks;
// Used to remember the custom class registration order.
static std::vector<StringName> class_register_order;
static MethodBind *bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const MethodDefinition &method_name, const void **p_defs, int p_defcount); static MethodBind *bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const MethodDefinition &method_name, const void **p_defs, int p_defcount);
static void initialize_class(const ClassInfo &cl); static void initialize_class(const ClassInfo &cl);
@ -178,6 +180,7 @@ void ClassDB::_register_class(bool p_virtual) {
cl.parent_ptr = &parent_it->second; cl.parent_ptr = &parent_it->second;
} }
classes[cl.name] = cl; classes[cl.name] = cl;
class_register_order.push_back(cl.name);
// Register this class with Godot // Register this class with Godot
GDExtensionClassCreationInfo class_info = { GDExtensionClassCreationInfo class_info = {

View File

@ -41,6 +41,7 @@ namespace godot {
std::unordered_map<StringName, ClassDB::ClassInfo> ClassDB::classes; std::unordered_map<StringName, ClassDB::ClassInfo> ClassDB::classes;
std::unordered_map<StringName, const GDExtensionInstanceBindingCallbacks *> ClassDB::instance_binding_callbacks; std::unordered_map<StringName, const GDExtensionInstanceBindingCallbacks *> ClassDB::instance_binding_callbacks;
std::vector<StringName> ClassDB::class_register_order;
GDExtensionInitializationLevel ClassDB::current_level = GDEXTENSION_INITIALIZATION_CORE; GDExtensionInitializationLevel ClassDB::current_level = GDEXTENSION_INITIALIZATION_CORE;
MethodDefinition D_METHOD(StringName p_name) { MethodDefinition D_METHOD(StringName p_name) {
@ -348,13 +349,15 @@ void ClassDB::initialize(GDExtensionInitializationLevel p_level) {
} }
void ClassDB::deinitialize(GDExtensionInitializationLevel p_level) { void ClassDB::deinitialize(GDExtensionInitializationLevel p_level) {
for (const std::pair<StringName, ClassInfo> pair : classes) { for (std::vector<StringName>::reverse_iterator i = class_register_order.rbegin(); i != class_register_order.rend(); ++i) {
const ClassInfo &cl = pair.second; const StringName &name = *i;
const ClassInfo &cl = classes[name];
if (cl.level != p_level) { if (cl.level != p_level) {
continue; continue;
} }
internal::gdextension_interface_classdb_unregister_extension_class(internal::library, cl.name._native_ptr()); internal::gdextension_interface_classdb_unregister_extension_class(internal::library, name._native_ptr());
for (auto method : cl.method_map) { for (auto method : cl.method_map) {
memdelete(method.second); memdelete(method.second);