-
-
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
Register server classes to fix GDNative binding issues #27936
Conversation
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.
I don't know what reasons were there to not expose those in the first place, so this might not be a good change, but if I assume there was no reason for that then this PR looks good!
24e5a0f
to
06b7f2c
Compare
modules/bullet/space_bullet.h
Outdated
@@ -73,7 +73,6 @@ class BulletPhysicsDirectSpaceState : public PhysicsDirectSpaceState { | |||
SpaceBullet *space; | |||
|
|||
public: | |||
BulletPhysicsDirectSpaceState(SpaceBullet *p_space); | |||
|
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.
clang-format
doesn't like the empty line after public
: https://travis-ci.org/godotengine/godot/jobs/523390022
Don't merge this. I'll review in an hour. |
Due to ClassDB not containing information about the server specific classes the JSON API file didn't contain those either which caused the GDNative binding tools to not recognize objects of such classes.
06b7f2c
to
aa65f6a
Compare
We do not want to expose these classes to the scripting API. The same way we don't expose godot/modules/mono/csharp_script.cpp Lines 1126 to 1130 in b0da7b6
Not sure how that could be applied to NativeScript. Maybe we could have a way to register private classes in ClassDB. |
Not sure what's the ground for not wanting to expose them, after all they are nothing but implementations of an already exposed interface. In the end it's your call, I just intended to contribute back the fix I did on my fork, considering that apparently other people ran into the same issue. Feel free to close the PR if you don't want to take this fix. |
First of all, I'm not talking for all contributors, as it can be seen in the two other contributors who approved this PR. One reason I don't like this is because all the reason to expose these classes is to fix the crash. There is no other point for these classes to be exposed, and the user is not meant to use them directly. This wouldn't be too much of a problem is we could somehow mark these classes so the C# bindings generator, for example, could generate them as The other reason, and the most important, is the case of |
It could be interesting if we would allow godot to support different features depending on the implementation chosen. Taking the physics as example we could have additional APIs depending on the physics engine, (For example the kinematic APIs that get rejected #21838), opening a lot of new possibilities. On the other hand, the down side is that it could mean start to break the base Godot architecture, since in this moment everything is unified. To say a rough opinion, in this moment, I'm at 51% on reject this PR, because I can add the extra features that I need elsewhere... |
That's an oversimplification. In practice what happens is that simply the binding is not aware of the object's type (as the inheritance relationship is unknown to it as it's not present in the API json), which then causes the crash.
I didn't look into that one, but if it's the same principle where there is an OS-specific subclass implementing a common interface, then I'm afraid the issue is the same. Really, there are two options as I see it:
IMO the API json itself should contain all interfaces though, even if some of the implementation classes only ever going to exist on a subset of the platforms/configurations. Again, it's up to you how you go about, as far as I'm concerned I have a working solution for the problem I encountered, so I won't have hard feelings about you closing the PR :) |
This will not happen. The ClassDB API has to be the same on all platforms and for all targets (debug/release). Maybe we could use the pimpl idiom to solve the |
The thing is this PR is missing more types that are not exposed. This is the full list:
An instance of any of those types that is returned to script code (be it C#, godot-cpp, etc) is vulnerable to the godotengine/godot-cpp#175 issue. Applying this fix to all of these types completely eliminates the point of the I think the better fix is to register the classes but still mark them as not exposed. Then each bindings generator can decide how to deal with them. There's still the problem of types like |
I didn't say otherwise, in fact we're in agreement. I just suggested that if we do have these "platform-optional" classes, those should be registered even if they aren't actually available on any particular platform, unless you use the pimpl idiom as you suggested. FWIW, I guess the ARVR classes are another example where the interface class itself is exposed, but there may not be actual implementations for them on all platforms. |
In a sense i don't think it's wrong to expose something like bulletphysicsserver if it's exposing extra features over the regular one (they need to be registered as virtual, though). The problem is that servers are wrapped into the multithread wrapper, so you don't really have access to them anyway. Maybe a different approach should be taken if we understand the actual use case. |
I'm still not sure what to do with this PR. I share @neikeq's concern over registering implementation classes which are not meant to user-facing, such as OS or library-specific implementations. I'm not sure how to fix the GDNative issue otherwise, but I feel this is not the right approach. BTW, I tried it locally to see if it would add the newly registered classes to the class reference, and
|
It's not only that concern, but doing this would break API portability, which is critical and the whole reason If a solution similar to what I proposed (which I use in C#) is not possible or not desired, then here is another option: Add a way to register classes as "internal" or "private". Those would be generated by bindings generators as any other class, but they would be generated as a private API not visible/exposed to user.
Neither this solution nor this PR's solution solve the following issue: it's hard to know what needs to be bound until you get a crash/error. Unless you were to just bind every single non-exposed class as internal. Ultimately, I prefer the solution I use in C#. Or a similar but better one if any one comes up with that. |
The crash described in the 3 related issues no longer happens. Has it been fixed or are we still looking for other solutions? (I notice my Type tags for Godot classes wouldn't be needed if we could access The implementation is straightforward: changes to Godot, changes to C++ binding. However, those 2 functions are unused in favor of |
So what is the status of this bug report? Is it waiting to be merged? |
Superseded by #34688. |
Due to ClassDB not containing information about the server specific classes
the JSON API file didn't contain those either which caused the GDNative
binding tools to not recognize objects of such classes.
This is needed to fix godotengine/godot-cpp#175.