-
-
Notifications
You must be signed in to change notification settings - Fork 22.1k
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
Prevent instantiating classes that aren't exposed #102440
Prevent instantiating classes that aren't exposed #102440
Conversation
46d8ca0
to
be81b06
Compare
Following you latest comment on the issue, I agree with this approach. Aside, I'm wondering if we're using two different terms to mean the same across the API and implementation: "internal" and "not exposed". If that's true, we may want to harominze the terminology. |
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.
This change seems correct to me. Notably, this also matches bindings_generator.cpp
behavior.
Anyone working with internal classes should probably instantiate through the C++ class interface.
The exception (as @dsnopek noted in the meeting) might be serialization, but we aren't aware of internal classes being serialized in this way.
I say we merge this early in the dev cycle, and if somebody or something complains, we may need to back paddle.
Side note, I did search through the code base a bit to find instances of internal classes and make some research, but was surprised to see GDREGISTER_INTERNAL_CLASS
isn't used once in the code base. So i didn't actually end up finding any.
The only usage was removed in #102433 as an alternative way to fix #99534. I'm fuzzy on why we have this feature in the first place though. It was added by @Daylily-Zeleen in #70329 but there wasn't much justification for why this is useful (no proposal). @dsnopek seemed to think it was a good addition though and I trust your judgement on that, but it might be worth to refresh our memory on the original context to see if this PR does what's expected, and whether this feature should be available for Godot classes if it was intended only for GDExtensions. |
See previous comment, would be good to check the context of the original PR implementing this feature.
So, we've had unexposed classes for a long time, however, they were registered by not explicitly registering them. Basically, if you used However, this pattern doesn't work as well for GDExtension, where we're registering all classes explicitly. That's why we needed Anyway, in short, PR #70329 didn't add the concept of unexposed classes (those existed for far longer), it just added a way to explicitly register them. This PR isn't really affected by whether or not a class is explicitly registered as unexposed or not. The problem still exists for unexposed classes that aren't explicitly registered (which is basically all the unexposed classes that exist within Godot itself). |
It seems involve multiple PRs/issues, I'm not sure if the response here is accurate. The initial Initial intention for "internal_class" (register by Like add custom |
Thanks! |
Originally from #99534
Currently, if you call
ClassDB::can_instantiate("...")
for an internal class, it will returntrue
, but most normal ways of instantiating the class in GDScript, GDExtension or C# won't work. However, they still can be created viaClassDB::instantiate("...")
. There's also no indication to GDExtension or scripting fromClassDB
that these classes can't be instantiated normally because we don't exposeClassDB::class_is_exposed()
.For example:
Do we even want internal classes to be instantiatable via
ClassDB::instantiate("...")
?This PR answers no, and makes it so that internal classes return
false
forClassDB::can_instantiate()
and can't be created viaClassDB::instantiate("...")
.I don't think there's anything that depends on the old behavior, but I'm not 100% sure, so treat this one with caution.