Skip to content
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

Update for new NOTIFICATION_POSTINITIALIZE handling #1568

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dsnopek
Copy link
Collaborator

@dsnopek dsnopek commented Aug 29, 2024

This adds support for the Godot changes from PR godotengine/godot#91018

With this change, we should finally be handling NOTIFICATION_POSTINITIALIZE in a way that matches how it works in Godot itself, which should allow (among other things) truly internal child nodes.

@Daylily-Zeleen If you have time, could you test that this works in your project?

Fixes #1567

@dsnopek dsnopek added the enhancement This is an enhancement on the current functionality label Aug 29, 2024
@dsnopek dsnopek added this to the 4.x milestone Aug 29, 2024
@dsnopek dsnopek requested a review from a team as a code owner August 29, 2024 19:19
@Daylily-Zeleen
Copy link
Contributor

Test this commit with MRP in this issue and v4.4.dev.custom_build [61598c5c8], not crsh occur.

@dsnopek
Copy link
Collaborator Author

dsnopek commented Sep 11, 2024

@Daylily-Zeleen I tested duplicating "MyNode" in your MRP, and it's working for me!

We still need someone who is not me (as the author of this PR) to review and approve it, though :-)

Copy link
Contributor

@Ivorforce Ivorforce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand most of this PR is just copied over code from the GDExtension reference. I had a quick check, it looks correct to me. Since it was tested already, I don't see why we shouldn't be able to push for a merge.

I noticed that we have a POSTINITIALIZE notification example in the example.cpp. Perhaps that should be updated?

@@ -292,7 +293,7 @@ typedef struct {
GDExtensionClassGetVirtual get_virtual_func; // Queries a virtual function by name and returns a callback to invoke the requested virtual function.
GDExtensionClassGetRID get_rid_func;
void *class_userdata; // Per-class user data, later accessible in instance bindings.
} GDExtensionClassCreationInfo; // Deprecated. Use GDExtensionClassCreationInfo3 instead.
} GDExtensionClassCreationInfo; // Deprecated. Use GDExtensionClassCreationInfo4 instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt anyone will see a deprecation comment. Is there a reason we are avoiding [[deprecated("Use GDExtensionClassCreationInfo4 instead.")]]?

Copy link
Collaborator Author

@dsnopek dsnopek Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This header is using a restricted subset of C: we want it to be possible to compile it with a C or C++ compiler, but it isn't meant to be "real code" because some bindings parse it, rather than compile it.

[[deprecated ...]] is a C++ thing, but even if it was C, I think we probably wouldn't use it anyway because it could create problems for bindings that manually parse the header.

FYI, I'd love to replace this with a JSON or XML definition that we generate the C code from, rather than the header being the definitive source.

if constexpr (!std::is_abstract_v<T>) {
T *new_object = memnew(T);
Wrapped::_set_construct_info<T>();
Copy link
Contributor

@Ivorforce Ivorforce Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By replacing the memnew call with this, does the change imply that any Object created with memnew will not have postinitialize called? Should godot-cpp users be using ClassDB::instantiate (or just this function) instead henceforth? If so, we should update the docs accordingly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR shouldn't change anything about how developers use godot-cpp, this should be a purely internal change within godot-cpp.

If you look a couple lines down, it will call _postinitialize(), but only if p_notify_postinitialize is true. We're not using memnew() because that should always lead to NOTIFICATION_POSTINITIALIZE, but here we need to be able to control whether we're doing it or not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh that makes sense. Thanks for explaining!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is an enhancement on the current functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[4.4] Need update create_instance_func because godot gdextension_interface.h upgrade
3 participants