-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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 exception when using base types of extension-based types from C# #75955
Conversation
76b9790
to
db99cdc
Compare
Apologies, I did not mean to close this. I was culling some old branches and happened to delete this one, which apparently closes the PR. This is still very much relevant. EDIT: Also, if there's anything I can do to help speed things up here, just let me know. |
I think this is a good temporary solution until the .NET module implements proper support for GDExtension classes. I haven't tested this very thoroughly, but it allows getting a GDExtension node with |
@raulsntos Would you mind giving this another look and an approval if you find it a good temp solution? |
I went ahead and rebased against latest master (593d5ca), just in case. I also updated the comments slightly. I also took the time to create a one-off build of my GDExtension that works with latest Godot master, which as of writing this is 593d5ca, and have included that in an MRP that you'll find below. I assume it'll be forward-compatible for the foreseeable future, but that's the specific commit I targeted if you need it. With this MRP you'll immediately run into the errors that prompted this PR to begin with, like not being able to create the instance binding for my I'll be honest and say that I have not tested this extensively, nor with any larger project, but the changes seem straight-forward enough that I don't see why they wouldn't scale. Anyway, here's the MRP: PR75955_MRP.zip (I was not able to sign this specific build for macOS, so you'll get the typical "untrusted developer" Gatekeeper warning if you try to run this on macOS, unfortunately.) Let me know if there's anything else I can do to help move things along. |
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.
Thanks for the MRP, it was very helpful. I also tested it a bit with Godot Rust, this PR will also fix an issue they were having (godot-rust/gdext#166).
The PR looks good to me so I'm approving.
Thanks! |
Fixes #74801.
This PR allows for GDExtension-based classes to be interacted with from C# so long as it's done through one of the engine-based base classes.
For example, without this fix the following code will cause a
NullReferenceException
when using a GDExtension-based physics server, because in such cases thestate
parameter must be backed by an extension class inheriting fromPhysicsDirectBodyState3DExtension
, which causes the C# integration to look for that extension class within theGodotSharp
assembly, which it won't find.This fix solves this (somewhat crudely) by traversing the class hierarchy when looking for the appropriate
ClassInfo
, and skipping them so long as it's a GDExtension class or its name happens to be eitherPhysicsServer2DExtension
orPhysicsServer3DExtension
. The exceptions for the physics server classes have to be made due to a workaround introduced in #59286 which explicitly filters them out when generating the C# bindings.Note that this fix doesn't do anything to solve the issue of actually exposing the GDExtension class itself to C#. If anything, this fix would probably get in the way of solving that problem, but I figured this could be a stopgap solution.
EDIT: MRP can be found here.