Unregister custom classes in reverse registration order
parent
82edc89cfa
commit
20be441026
|
@ -105,6 +105,8 @@ private:
|
|||
// This may only contain custom classes, not Godot classes
|
||||
static std::unordered_map<StringName, ClassInfo> classes;
|
||||
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 void initialize_class(const ClassInfo &cl);
|
||||
|
@ -178,6 +180,7 @@ void ClassDB::_register_class(bool p_virtual) {
|
|||
cl.parent_ptr = &parent_it->second;
|
||||
}
|
||||
classes[cl.name] = cl;
|
||||
class_register_order.push_back(cl.name);
|
||||
|
||||
// Register this class with Godot
|
||||
GDExtensionClassCreationInfo class_info = {
|
||||
|
|
|
@ -41,6 +41,7 @@ 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;
|
||||
GDExtensionInitializationLevel ClassDB::current_level = GDEXTENSION_INITIALIZATION_CORE;
|
||||
|
||||
MethodDefinition D_METHOD(StringName p_name) {
|
||||
|
@ -348,13 +349,15 @@ void ClassDB::initialize(GDExtensionInitializationLevel p_level) {
|
|||
}
|
||||
|
||||
void ClassDB::deinitialize(GDExtensionInitializationLevel p_level) {
|
||||
for (const std::pair<StringName, ClassInfo> pair : classes) {
|
||||
const ClassInfo &cl = pair.second;
|
||||
for (std::vector<StringName>::reverse_iterator i = class_register_order.rbegin(); i != class_register_order.rend(); ++i) {
|
||||
const StringName &name = *i;
|
||||
const ClassInfo &cl = classes[name];
|
||||
|
||||
if (cl.level != p_level) {
|
||||
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) {
|
||||
memdelete(method.second);
|
||||
|
|
Loading…
Reference in New Issue