Fix Object::cast_to<T>() for custom classes (reverted)#1037
Fix Object::cast_to<T>() for custom classes (reverted)#1037akien-mga merged 1 commit intogodotengine:masterfrom
Conversation
|
Hm, maybe this needs something a little more. I'm now seeing issues with non-custom classes! I don't yet understand "why" though, since they should also have RTTI information that UPDATE: Nevermind, I think this is separate issue because it's only happening when getting an |
|
Seeing as how RTTI is right up there with exception handling in terms of hard lines that divide the C++ ecosystem, I'm curious what the stance of godot-cpp is when it comes to allowing the disabling of RTTI. The code in this PR would, as far as I can tell, be the only thing that would require it to be enabled. There is one usage of godot-cpp/include/godot_cpp/templates/rid_owner.hpp Lines 317 to 321 in f9ccf28 Anyway, don't take this as a review or anything. I just happened to stumble upon your PR and it caught my attention. It might very well be that your proposed solution is the only reasonable way of solving this problem. |
|
Likewise, |
|
Thanks! |
Fixes #995 and godotengine/godot#71332
I tried a bunch of different variations on this, including using
p_object->is_class(class_name)to check if the object was the right type, AND making changes in the Godot engine itself ingdextension_object_cast_to()(which would break the GDExtension ABI, but Remi actually said that would be fine while GDExtension is experimental :-)).However, assuming there isn't some case where this won't work that I didn't think of, I like the version in this PR the best so far!
It's switching to
dynamic_cast<T>at the end, which means C++ will check if the final class matches the requested type using RTTI. This should be much faster thanp_object->is_class(class_name)(since that relies on walking up the inheritance chain and comparing strings).Anyway, it's working in my testing with SG Physics 2D!