-
-
Notifications
You must be signed in to change notification settings - Fork 23.8k
GDExtension: Always run shutdown callback before deinitializing any levels #107594
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: Always run shutdown callback before deinitializing any levels #107594
Conversation
| if (level >= 0) { // Already initialized up to some level. | ||
| // Deinitialize down from current level. | ||
| for (int32_t i = level; i >= GDExtension::INITIALIZATION_LEVEL_CORE; i--) { | ||
| p_extension->deinitialize_library(GDExtension::InitializationLevel(i)); | ||
| } | ||
| } |
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 know this code just moved, but something I noticed is the use of level >= 0 (ordinal number), but then
i >= GDExtension::INITIALIZATION_LEVEL_CORE (constant, but with implicit knowledge that CORE == 0).
The if is not really necessary at all, is it?
Values are defined as follows:
godot/core/extension/gdextension_interface.h
Lines 729 to 735 in 46c495c
| typedef enum { | |
| GDEXTENSION_INITIALIZATION_CORE, | |
| GDEXTENSION_INITIALIZATION_SERVERS, | |
| GDEXTENSION_INITIALIZATION_SCENE, | |
| GDEXTENSION_INITIALIZATION_EDITOR, | |
| GDEXTENSION_MAX_INITIALIZATION_LEVEL, | |
| } GDExtensionInitializationLevel; |
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.
GDExtensionManager::level defaults to -1:
| int32_t level = -1; |
... which is used to indicate that we haven't been initialized up to any level yet. So, I think this if is still necessary.
I don't know that this is done in the clearest possible way, but it's not something I think we need to address in this PR :-)
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.
But in the case of level == -1, this for loop:
for (int32_t i = level; i >= GDExtension::INITIALIZATION_LEVEL_CORE; i--)would run as:
for (int32_t i = -1; i >= 0; i--)i.e. never -- so I don't think the if is needed.
I agree it doesn't have to be part of this PR, just noticed it during review.
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.
Oh, I see what you're saying now! Yeah, I think you're right :-)
Let's leave it be in this PR, though
478212f to
32cf8fd
Compare
|
I think you mentioned it @dsnopek, but I don't remember: what was the reason again for Also in light of the godotengine/godot-proposals#12622 initiative, which wants to move hardcoded .h functionality to the .json file 🙂 |
It's to make a GDExtension equivalent to There are some workarounds, but they are awkward. For example, with the the |
|
Thank you very much! 👍 |
32cf8fd to
3b7e345
Compare
Sure, I added this additional comment: |
Bromeon
left a comment
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 a lot! 🙂
|
Thanks! |
This is a small fix to PR #106030
When normal shutdown occurs, the shutdown callbacks are run before any of the initialization levels are deinitialized. So, when an extension is unloaded before Godot is shutdown, it should also run it before any of the initialization levels are deinitialized, which is what this PR does.
(The diff is a little weird, because it removes and adds code that was already there, not the code added by the referenced PR. But the result is the same: the order of the two things are swapped.)
I also snuck in a couple tiny comments to document these callbacks in
gdextension_interface.h, which was discussed at the last GDExtension team meeting. If it'd be better to move that to its own PR, I can, but these changes are minor fix ups to the same new feature so I thought it may be OK :-)