Skip to content

Improve initializations order, especially with regards to type registration, physics, and navigation. #106875

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

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

Conversation

Ivorforce
Copy link
Member

@Ivorforce Ivorforce commented May 27, 2025

I've used the warnings introduced in #106873 to sanitize initialization order a bit, reducing the number of warnings by a few tens.
This may fix some subtle bugs, but may also introduce regressions if I've changed anything incorrectly. Hopefully though, it should be better overall than before.

This should be the hardest part of fixing the warnings introduced by #106873. Most of the rest should be switching to GDSOFTCLASS, or adding GDREGISTER_CLASS calls in the appropriate spots.

Tagging @smix8 and @mihe for navigation and physics changes, respectively.

Changes

  • register_core_types registers important types first (Object, RefCounted, etc.)
    • Other registrations are moved around to be in correct order.
  • Many classes are now registered before creating the singletons.
  • register_server_types is called before creating server singletons.
    • Physics servers are created and registered right after one another, coupling the parts closer together.
  • register_scene_types is called before creating scene singletons.
    • Previously, some navigation initialization was happening here. I moved this to the navigation server initialization functions.
  • GDScript editor types are registered and handled during EDITOR initialization instead of SERVERS, as this is where it's expected.
  • Websockets are initialized during SCENE instead of CORE, as this is where it's expected.
  • Some macOS classes are made to be GDSOFTCLASS as they're not meant to be exposed. This should be followed up with similar changes for other platforms.
  • register_scene_types and register_server_types are rearranged for expected order.
  • Possibly more I forgot.

@Ivorforce Ivorforce added this to the 4.x milestone May 27, 2025
@Ivorforce Ivorforce requested review from mihe and smix8 May 27, 2025 15:47
@Ivorforce Ivorforce requested review from a team as code owners May 27, 2025 15:47
@Ivorforce Ivorforce requested review from a team as code owners May 27, 2025 15:47
@Ivorforce Ivorforce force-pushed the object-type-register-order-first-fix branch from 8c75ba8 to 8199c68 Compare May 27, 2025 16:00
@Ivorforce Ivorforce requested review from a team as code owners May 27, 2025 16:00
@@ -139,6 +139,7 @@ static void _editor_init() {
void initialize_gdscript_module(ModuleInitializationLevel p_level) {
if (p_level == MODULE_INITIALIZATION_LEVEL_SERVERS) {
GDREGISTER_CLASS(GDScript);
GDREGISTER_ABSTRACT_CLASS(GDScriptNativeClass);
Copy link
Member

Choose a reason for hiding this comment

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

As far as I know, GDScriptNativeClass is not supposed to be exposed.

Copy link
Member Author

@Ivorforce Ivorforce May 27, 2025

Choose a reason for hiding this comment

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

It's using _bind_methods though to bind new.
Perhaps it is supposed to be registered as internal?

Or i can stay agnostic and remove this change for now :)

Copy link
Member

Choose a reason for hiding this comment

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

This is more of a hack due to the lack of first-class types. GDScriptNativeType instances are obtainable, you can use them like Node.new() and is_instance_of(object, Node), but they were never meant to be exposed.

@Ivorforce Ivorforce force-pushed the object-type-register-order-first-fix branch from 8199c68 to a7b144b Compare May 27, 2025 16:40
@Ivorforce Ivorforce force-pushed the object-type-register-order-first-fix branch from a7b144b to 75e6d44 Compare May 27, 2025 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants