-
-
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
Ensure GDExtension class is the correct type for the Godot engine class #1050
Conversation
48f2920
to
c982c63
Compare
My latest update does the following:
So, once the CI has passed, I'm going to take this out of Draft! (NOTE: just to make this absolutely clear, we don't need this for 4.0 stable - this can wait for 4.x :-)) |
c982c63
to
4822090
Compare
4822090
to
00122bc
Compare
d0093c7
to
76ab02b
Compare
Converting to a draft while PR godotengine/godot#76406 is in progress |
76ab02b
to
8ad7d09
Compare
I've updated this to be based on godotengine/godot#76406 So, this'll need to wait until at least that one is merged before this can come out of draft again.
UPDATE: I don't want to delay this any more :-) |
8ad7d09
to
2474962
Compare
2474962
to
431e30b
Compare
This is finally really ready for review! I've also put it on the agenda for the next GDExtension meeting :-) |
Discussed at the GDExtension meeting, and overall the solution makes sense. @vnen is going to do code review |
Hey do you need any help here? I hate to be that guy but that bug was unacceptable. Are there unit tests for this? If not I could look into writing some. |
I'm planning to add tests for this once #1101 is merged! I just didn't want to (potentially) delay this one by basing it on that one. Hopefully, they'll both be merged soon :-) |
Thanks so much for this, I was waiting for it! Can't wait to update and try it :) |
As discovered after merging PR #1037 (which was later reverted), when a Godot engine class is created on the Godot side and then passed to GDExtension, the GDExtension class that is created may not be of the correct type (most often it'll be created as
godot::Object
and then be unsafely cast to the correct class, which could lead to strange/incorrect behavior later).This is explained in detail in these two comments:
Object::cast_to
works incorrectly for GDExtension custom classes #995 (comment)This PR aims to ensure that the GDExtension class that's created to wrap a Godot engine class always matches the Godot class it wraps.
This is a draft currently, because there is still more that I'd like to do:
This isn't as efficient as it could be. We're always looking up the instance binding callbacks, even when we don't need them (which would be the case for any class created on the GDExtension side)I'd like to make a utility method somewhere to correctly convert from aGodotObject*
to agodot::Object
, rather than have it only exist inVariant::operator Object*()
As pointed out by @zhehangd inObject::cast_to
works incorrectly for GDExtension custom classes #995 (comment), there are more places in godot-cpp that need to be fixed (for which we'll use the utility function)This depends on PR godotengine/godot#73511 to the Godot engine, because a new function needs to be added to the GDExtension interface.
UPDATE: Back in draft, since I'm rebasing this on godotengine/godot#76406UPDATE: godotengine/godot#76406 was merged, so I'm taking this out of draft!
Fixes #995