From ec6e51b3a4bbd649655ed9343bfc3171ce2cb856 Mon Sep 17 00:00:00 2001 From: David Snopek Date: Thu, 6 Jul 2023 21:39:19 -0500 Subject: [PATCH] Handle missing instance binding callbacks by finding the closest parent (cherry picked from commit 52ca3ef547b5586fd0a085c5b01a08b8f95332ca) --- src/core/class_db.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/core/class_db.cpp b/src/core/class_db.cpp index 863d97bf..702df993 100644 --- a/src/core/class_db.cpp +++ b/src/core/class_db.cpp @@ -318,7 +318,18 @@ GDExtensionClassCallVirtual ClassDB::get_virtual_func(void *p_userdata, GDExtens const GDExtensionInstanceBindingCallbacks *ClassDB::get_instance_binding_callbacks(const StringName &p_class) { std::unordered_map::iterator callbacks_it = instance_binding_callbacks.find(p_class); - ERR_FAIL_COND_V_MSG(callbacks_it == instance_binding_callbacks.end(), nullptr, String("Cannot find instance binding callbacks for class '{0}'.").format(Array::make(p_class))); + if (likely(callbacks_it != instance_binding_callbacks.end())) { + return callbacks_it->second; + } + + // If we don't have an instance binding callback for the given class, find the closest parent where we do. + StringName class_name = p_class; + do { + class_name = get_parent_class(class_name); + ERR_FAIL_COND_V_MSG(class_name == StringName(), nullptr, String("Cannot find instance binding callbacks for class '{0}'.").format(Array::make(p_class))); + callbacks_it = instance_binding_callbacks.find(class_name); + } while (callbacks_it == instance_binding_callbacks.end()); + return callbacks_it->second; }