-
-
Notifications
You must be signed in to change notification settings - Fork 22k
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
GDExtension: create_instance_func
can be NULL to inhibit construction from GDScript
#65542
GDExtension: create_instance_func
can be NULL to inhibit construction from GDScript
#65542
Conversation
718dc73
to
7fb4a64
Compare
The 2nd commit reuses duplicate code in a common method. |
2b731ef
to
3f483eb
Compare
8da855a
to
c7fea96
Compare
Fixed a few issues, encountered a null pointer dereference of godot/modules/gdscript/tests/gdscript_test_runner.cpp Lines 558 to 565 in 2116318
I'd need to check why this happens exactly. The first commit passed CI, so probably I introduced a mistake during the refactoring. Edit: fixed, bad parentheses in boolean condition |
c7fea96
to
300ecb0
Compare
There's a pending related discussion: Can we support a |
… from GDScript This can be useful for classes which should either not be instantiated (e.g. only static methods) or only instantiated from the GDExtension binding. In practice, this causes a descriptive error message if `MyClass.new()` is used in GDScript.
a011fab
to
b24bb58
Compare
Oof, sorry for the excessive tagging -- I merged latest Should be fixed now, but unfortunately the review requests don't go away. |
PR review meeting: may be superseeded by #66979. If that's the case, we could close this PR. |
This is a small quality-of-life change that's useful for classes which should either not be instantiated (e.g. static methods) or only instantiated from the GDExtension binding. The GDScript constructor call
MyClass.new()
now causes an error, which has the nice side effect that forgetting to specifycreate_instance_func
leads to a clear error rather than a half-constructed object.Currently, the code already checks for the condition:
so the API header comment
/* this one is mandatory */
is wrong. However, theClassDB
code doesn't act upon the null pointer, instead it constructs a "zombie" instance with initialized base but uninitialized extension.The check at the bottom of the function,
if (ti->native_extension && ti->native_extension->create_instance)
could now theoretically be simplified to:
if (ti->native_extension)
however I'm not sure if that's desired, as another refactoring might quickly introduce UB (null pointer dereferencing).