-
-
Notifications
You must be signed in to change notification settings - Fork 575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix cast_to
for non-exposed engine types
#365
Conversation
@sheepandshepherd could you check why travis wasn't happy with your fix? |
96459f5
to
f100d7f
Compare
Looks like it just needed the updated 3.2 headers. Thanks for merging those. Travis is happy after a rebase. |
Hey, I'd like to voice my support for the PR. It actually fixes an issue I have been running into on macOS, and quashes my fears regarding sharing RTTI data across binaries. Let me summarize the issue I ran into that this PR fixes:
The bug I was running into specifically on Mac and with this combination of engine is that Object::cast_to returns null, even though I made absolutely sure that targetNode was indeed a Spatial. My conclusion therefore was that RTTI's typeid().hash_code() was crossing ABI boundaries, and due to a nuance with how I compiled it, that caused the cast_to comparison to fail. I tested both with and without this patch in two separate builds just in case RTTI was random..I suppose that's still possible given that std::type_info::hash_code is random and offers no uniqueness guarantees(!) but HIGHLY unlikely. Anyway, in both sets of builds, I can confirm that this PR fixes my issue on my particular macOS environment in my particular GDNative module in my particular application. I know that's not much to go on, but I think it's a great change regardless! |
I still need to understand the changes in the PR (notably the new class header items), but, but there are conflicts to be resolved before it can be merged. Is that fixing the potential crash that would occur when doing stuff like |
No, those are a different issue. Ref just needs to use Currently, it always fails to cast objects of non-exposed types like Godot already has a The function itself is exposed to GDNative already as well, as I'll fix the merge conflicts in a bit, and also rename the |
Yeah I think I'll work on removing all |
Apparently double underscores are reserved anywhere in names in the C++ standard, but Microsoft uses slightly different wording reserving them only at the beginning. Maybe we can use |
f100d7f
to
c2ff17a
Compare
|
I see you made it so Godot classes now have a specific godot-cpp/include/core/Godot.hpp Line 103 in 1600019
The wrong ID will be returned here |
c2ff17a
to
ebdffe9
Compare
Thanks, I missed that one. |
include/core/Godot.hpp
Outdated
|
||
if (godot::_TagDB::is_type_compatible(typeid(T).hash_code(), have_tag)) { | ||
return (T::___CLASS_IS_SCRIPT) ? detail::get_custom_class_instance<T>(obj) : (T *)obj; | ||
if (godot::_TagDB::is_type_compatible(typeid(T).hash_code(), have_tag)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we can encapsulate this typeid(T).hash_code()
by using __get_id()
instead?
ebdffe9
to
33f9de1
Compare
Thanks! |
This PR changes how
Object::cast_to<T>(o)
checks o's type when T is an engine class.TagDB
would fail on instances of non-exposed types likeBulletPhysicsDirectSpaceState
. Instead, engine types are now type-checked by the engine's owncast_to
implementation, which doesn't require GDNative to have type tag/parent info about internal types. NativeScripts continue to be checked withTagDB
.Related to #175, godotengine/godot#28195, and godotengine/godot#28574, but they were actually fixed already. This only fixes casts affected by the same issue.
(Depends on godotengine/godot#34688 and updated godot_headers.)