Handle missing instance binding callbacks by finding the closest parent#1165
Handle missing instance binding callbacks by finding the closest parent#1165dsnopek merged 1 commit intogodotengine:masterfrom
Conversation
The problem is that the class is now called I added this patch: diff --git a/binding_generator.py b/binding_generator.py
index d04c698..7d6f6e7 100644
--- a/binding_generator.py
+++ b/binding_generator.py
@@ -1453,7 +1506,10 @@ def generate_engine_class_source(class_api, used_classes, fully_used_classes, us
if is_singleton:
result.append(f"{class_name} *{class_name}::get_singleton() {{")
- result.append(f"\tconst StringName _gde_class_name = {class_name}::get_class_static();")
+ if class_name != "ClassDBSingleton":
+ result.append(f"\tconst StringName _gde_class_name = {class_name}::get_class_static();")
+ else:
+ result.append(f"\tstatic const StringName _gde_class_name = StringName(\"ClassDB\");")
result.append(
"\tstatic GDExtensionObjectPtr singleton_obj = internal::gdextension_interface_global_get_singleton(_gde_class_name._native_ptr());"
)
@@ -1480,7 +1536,10 @@ def generate_engine_class_source(class_api, used_classes, fully_used_classes, us
result.append(method_signature + " {")
# Method body.
- result.append(f"\tconst StringName _gde_class_name = {class_name}::get_class_static();")
+ if class_name != "ClassDBSingleton":
+ result.append(f"\tconst StringName _gde_class_name = {class_name}::get_class_static();")
+ else:
+ result.append(f"\tstatic const StringName _gde_class_name = StringName(\"ClassDB\");")
result.append(f'\tconst StringName _gde_method_name = "{method["name"]}";')
result.append(
f'\tstatic GDExtensionMethodBindPtr _gde_method_bind = internal::gdextension_interface_classdb_get_method_bind(_gde_class_name._native_ptr(), _gde_method_name._native_ptr(), {method["hash"]});'
And now everything seems to be working as before. No errors, no crashes, at first glance. Here is the action in my repository with this PR. (+9 MB for I hope this shouldn't affect performance too much. I didn't notice a major performance decrease overall. I decided to try to compare the performance of the code that previously displayed a lot of errors. I didn't see any noticeable difference. Detailsvoid DebugDraw::test_tree_process() {
uint64_t start_time = TIME()->get_ticks_usec();
String editor3d = "Node3DEditorViewportContainer";
String subviewport = SubViewport::get_class_static();
Node *res = Utils::find_node_by_class(SCENE_ROOT(), editor3d);
Node *n = res->get_child(0)->get_child(0);
UtilityFunctions::print("Test processed: ", TIME()->get_ticks_usec() - start_time);
}
Node *Utils::find_node_by_class(Node *start_node, const String &class_name) {
for (int i = 0; i < start_node->get_child_count(); i++) {
auto c = start_node->get_child(i);
if (c->get_class() == class_name)
return c;
auto nc = find_node_by_class(c, class_name);
if (nc)
return nc;
}
return nullptr;
}
#define SCENE_ROOT() (Object::cast_to<SceneTree>(Engine::get_singleton()->get_main_loop())->get_root())
#define TIME() Time::get_singleton()First runs: Second runs: Without this PR, with excluded unused classes and with fixed crashes, the output looks like this: |
4539169 to
088c3a2
Compare
Thanks for the patch! I've integrated it into PR #1164 and rebased this PR on that.
That's awesome! Thanks for testing it ❤️ |
|
Discussed at the GDExtension meeting, and we think this PR makes sense! However, it needs to wait on getting access to the |
d495408 to
52ca3ef
Compare
BastiaanOlij
left a comment
There was a problem hiding this comment.
Reviewed during GDExtension meeting, this looks like a good fix.
|
Cherry-picked for 4.1 in PR #1261 |

This attempts to solve a problem that was brought up on issue #1160 (although, this PR doesn't solve that issue).
Basically, the problem is that we assume we'll have the instance binding callbacks for any valid wrapper class. If we don't have the wrapper class, we output an error message and use
Object.However, in either of these cases:
... we want to do what we're already doing for unexposed classes, which is to find the closest parent class that we do know about.
This will only output an error message, if we're unable to find any ancestor classes that we know about.
This depends on PR #1164 which is currently a draft. So, marking this one as a draft too!
Fixes #1163