Skip to content

Editor crashes on shutdown when fetching a singleton via Engine #1900

Open

Description

@Naros

Godot version

4.6.beta2

godot-cpp version

4.5.0.stable sync and b724219

System information

Windows 11. I should note that on Linux, I do not observe this behavior, and unfortunately, I do not have a MacOS system to verify whether this problem exists there or not.

Issue description

When using the following logic in an empty GDExtension:

void initialize_extension_module(ModuleInitializationLevel p_level) {
  if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) {
    for (const String& singleton_name : Engine::get_singleton()->get_singleton_list()) {
      Object* o = Engine::get_singleton()->get_singleton(singleton_name);
    }
  }
}

On Windows, when the editor closes, this leads to

[0] <couldn't map PC to fn name>
[1] Object::~Object (core\object\object.cpp:2436)
[2] GDExtensionManager::`scalar deleting destructor`
[3] unregister_core_types (core\register_core_types.cpp:427)
[4] Main::cleanup (main\main.cpp:5229)
[5] widechar_main (platform\windows\godot_windows.cpp:105)
[6] _main (platform\windows\godot_windows.cpp:128)
[7] main (platform\windows\godot_windows.cpp:140)

Steps to reproduce

See code snippet above.

Minimal reproduction project

N/A

Activity

  1. Naros commented on Jan 5, 2026

    @Naros
    ContributorAuthor

    As discussed in dev chat, this seems to be related to #1458. Apply this in the Engine method call addresses the issue, although we recognize this isn't the right fix

    Object* obj = internal::_call_native_mb_ret_obj<Object>(_gde_method_bind, _owner, &p_name);
    ClassDB::_register_engine_singleton(p_name, obj);
    return obj;
    
  2. dsnopek commented on Jan 5, 2026

    @dsnopek
    Collaborator

    On chat, I asked @Naros to test changing Object *Engine::get_singleton(const StringName &) to this code:

    Object *Engine::get_singleton(const StringName &p_name) const {
    	static GDExtensionMethodBindPtr _gde_method_bind = ::godot::gdextension_interface::classdb_get_method_bind(Engine::get_class_static()._native_ptr(), StringName("get_singleton")._native_ptr(), 1371597918);
    	CHECK_METHOD_BIND_RET(_gde_method_bind, (nullptr));
    	Object *obj = ::godot::internal::_call_native_mb_ret_obj<Object>(_gde_method_bind, _owner, &p_name);
    	ClassDB::_register_engine_singleton(p_name, singleton);
    	return obj;
    }

    ... and he said it fixed the issue for him!

    So, I think the problem is that the fix we added in #1458 only applied to the classes static get_singleton() methods and we need to make sure the same applies to Object *Engine::get_singleton(const StringName &)

    UPDATE: Oops, cross post :-)

  3. added theissue type on Jan 5, 2026
  4. removed theissue type on Jan 5, 2026
  5. added this to the 4.x milestone on Jan 5, 2026
  6. Naros commented on Jan 22, 2026

    @Naros
    ContributorAuthor

    Hi @dsnopek did you find any resolution for this at all?

  7. dsnopek commented on Jan 22, 2026

    @dsnopek
    Collaborator

    I've spent a couple hours trying to find the right solution, and haven't quite gotten there yet.

    My original idea was that the singletons' constructors could set singleton and call _register_engine_singleton(), rather than having the static get_singleton() do it, so the right thing would happen for singletons no matter how they were constructed. However, that ran into a ton of different problems, so I'm back to the drawing board.

    I may end up pursuing a solution similar to the change in the comments above, even if it's not ideal

  8. Naros commented on Jan 23, 2026

    @Naros
    ContributorAuthor

    Is this something that you believe will make its way into 4.6.0-stable or likely slip?

  9. modified the milestones: 4.x, 10.x on Jan 23, 2026
  10. dsnopek commented on Jan 23, 2026

    @dsnopek
    Collaborator

    It turns out trying to do something like the comments above also had problems, so I've gone back to the constructor approach - it's seems the least bad/weird of the two :-)

    I just posted PR #1908 with a potential fix - please let me know if it work for you!

  11. CycloneRing commented on Jun 23, 2026

    @CycloneRing

    I experience the same issue when using the Time singleton. However, I’ve noticed that the crash only occurs on exit when running official Godot builds. It doesn’t happen with my own compiled version from same exact codebase/commit. I suspect the difference is that the official Windows builds are compiled with MinGW, while I compile mine using MSVC.

  12. Naros commented on Jun 24, 2026

    @Naros
    ContributorAuthor

    Hi @CycloneRing, I don't think it's a MinGW vs MSVC issue, as I used VS2022 previously and had the same problem.

  13. Ivorforce commented on Jul 28, 2026

    @Ivorforce
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis has been identified as a bugcrash

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions