Skip to content

ClassDB AHashMap segmentation fault #1884

Closed

Description

@Withaust

Godot version

4.5.1.stable

godot-cpp version

4.5

System information

Windows 10

Issue description

Image
game.windows.editor.dev.x86_64.dll!godot::AHashMap<godot::StringName, godot::ClassDB::ClassInfo::VirtualMethod, godot::HashMapHasherDefault, godot::HashMapComparatorDefault<godot::StringName> >::_lookup_pos_with_hash(const godot::AHashMap<godot::StringName, godot::ClassDB::ClassInfo::VirtualMethod, godot::HashMapHasherDefault, godot::HashMapComparatorDefault<godot::StringName> > * const this, const godot::StringName & p_key, uint32_t & r_pos, uint32_t & r_hash_pos, uint32_t p_hash) (a:\Recusant\godot-cpp\include\godot_cpp\templates\a_hash_map.hpp:136)
game.windows.editor.dev.x86_64.dll!godot::AHashMap<godot::StringName, godot::ClassDB::ClassInfo::VirtualMethod, godot::HashMapHasherDefault, godot::HashMapComparatorDefault<godot::StringName> >::_lookup_pos(const godot::AHashMap<godot::StringName, godot::ClassDB::ClassInfo::VirtualMethod, godot::HashMapHasherDefault, godot::HashMapComparatorDefault<godot::StringName> > * const this, const godot::StringName & p_key, uint32_t & r_pos, uint32_t & r_hash_pos) (a:\Recusant\godot-cpp\include\godot_cpp\templates\a_hash_map.hpp:127)
game.windows.editor.dev.x86_64.dll!godot::AHashMap<godot::StringName, godot::ClassDB::ClassInfo::VirtualMethod, godot::HashMapHasherDefault, godot::HashMapComparatorDefault<godot::StringName> >::find(const godot::AHashMap<godot::StringName, godot::ClassDB::ClassInfo::VirtualMethod, godot::HashMapHasherDefault, godot::HashMapComparatorDefault<godot::StringName> > * const this, const godot::StringName & p_key) (a:\Recusant\godot-cpp\include\godot_cpp\templates\a_hash_map.hpp:579)
game.windows.editor.dev.x86_64.dll!godot::ClassDB::get_virtual_func(void * p_userdata, GDExtensionConstStringNamePtr p_name, uint32_t p_hash) (a:\Recusant\godot-cpp\src\core\class_db.cpp:300)
Node::_gdvirtual__enter_tree_call(Node * const this) (a:\Recusant\godot\scene\main\node.h:397)
Node::_propagate_enter_tree(Node * const this) (a:\Recusant\godot\scene\main\node.cpp:343)
Node::_set_tree(Node * const this, SceneTree * p_tree) (a:\Recusant\godot\scene\main\node.cpp:3319)
Node::_add_child_nocheck(Node * const this, Node * p_child, const StringName & p_name, Node::InternalMode p_internal_mode) (a:\Recusant\godot\scene\main\node.cpp:1670)
Node::add_child(Node * const this, Node * p_child, bool p_force_readable_name, Node::InternalMode p_internal) (a:\Recusant\godot\scene\main\node.cpp:1700)
call_with_ptr_args_helper<__UnexistingClass, Node*, bool, Node::InternalMode, 0ull, 1ull, 2ull>(__UnexistingClass * p_instance, void (__UnexistingClass::*)(__UnexistingClass * const, Node *, bool, Node::InternalMode) p_method, const void ** p_args) (a:\Recusant\godot\core\variant\binder_common.h:244)
call_with_ptr_args<__UnexistingClass, Node*, bool, Node::InternalMode>(__UnexistingClass * p_instance, void (__UnexistingClass::*)(__UnexistingClass * const, Node *, bool, Node::InternalMode) p_method, const void ** p_args) (a:\Recusant\godot\core\variant\binder_common.h:492)
MethodBindT<Node*, bool, Node::InternalMode>::ptrcall(const MethodBindT<Node*, bool, Node::InternalMode> * const this, Object * p_object, const void ** p_args, void * r_ret) (a:\Recusant\godot\core\object\method_bind.h:360)
gdextension_object_method_bind_ptrcall(GDExtensionMethodBindPtr p_method_bind, GDExtensionObjectPtr p_instance, const GDExtensionConstTypePtr * p_args, GDExtensionTypePtr p_ret) (a:\Recusant\godot\core\extension\gdextension_interface.cpp:1336)
game.windows.editor.dev.x86_64.dll!godot::internal::_call_native_mb_no_ret<void**, signed char*, long long*>(const GDExtensionMethodBindPtr mb, void * instance) (a:\Recusant\godot-cpp\include\godot_cpp\core\engine_ptrcall.hpp:67)
game.windows.editor.dev.x86_64.dll!godot::Node::add_child(godot::Node * const this, godot::Node * p_node, bool p_force_readable_name, godot::Node::InternalMode p_internal) (a:\Recusant\godot-cpp\gen\src\classes\node.cpp:87)
game.windows.editor.dev.x86_64.dll!core::Bootstrap::_ready(core::Bootstrap * const this) (a:\Recusant\recusant\sources\core\system\bootstrap.cpp:210)
game.windows.editor.dev.x86_64.dll!godot::call_with_ptr_args_helper<core::Bootstrap>(core::Bootstrap*, void (core::Bootstrap::*)(), void const* const*, godot::IndexSequence<>)(core::Bootstrap * p_instance, void (core::Bootstrap::*)(core::Bootstrap * const) p_method, const GDExtensionConstTypePtr * p_args) (a:\Recusant\godot-cpp\include\godot_cpp\core\binder_common.hpp:193)
game.windows.editor.dev.x86_64.dll!godot::call_with_ptr_args<core::Bootstrap>(core::Bootstrap * p_instance, void (core::Bootstrap::*)(core::Bootstrap * const) p_method, const GDExtensionConstTypePtr * p_args) (a:\Recusant\godot-cpp\include\godot_cpp\core\binder_common.hpp:213)
game.windows.editor.dev.x86_64.dll!godot::Node::register_virtuals<core::Bootstrap, godot::Node>()::{lambda(void*, void const* const*, void*)#3}::operator()(void*, void const* const*, void*) const(const struct {...} * const __closure, GDExtensionObjectPtr p_instance, const GDExtensionConstTypePtr * p_args, GDExtensionTypePtr p_ret) (a:\Recusant\godot-cpp\gen\include\godot_cpp\classes\node.hpp:359)
game.windows.editor.dev.x86_64.dll!godot::Node::register_virtuals<core::Bootstrap, godot::Node>()::{lambda(void*, void const* const*, void*)#3}::_FUN(void*, void const* const*, void*)() (a:\Recusant\godot-cpp\gen\include\godot_cpp\classes\node.hpp:359)
Node::_gdvirtual__ready_call(Node * const this) (a:\Recusant\godot\scene\main\node.h:399)
Node::_notification(Node * const this, int p_notification) (a:\Recusant\godot\scene\main\node.cpp:266)
Node::_notification_forwardv(Node * const this, int p_notification) (a:\Recusant\godot\scene\main\node.h:48)
Object::_notification_forward(Object * const this, int p_notification) (a:\Recusant\godot\core\object\object.cpp:931)
Object::notification(Object * const this, int p_notification, bool p_reversed) (a:\Recusant\godot\core\object\object.h:893)
Node::_propagate_ready(Node * const this) (a:\Recusant\godot\scene\main\node.cpp:317)
Node::_propagate_ready(Node * const this) (a:\Recusant\godot\scene\main\node.cpp:308)
Node::_set_tree(Node * const this, SceneTree * p_tree) (a:\Recusant\godot\scene\main\node.cpp:3321)
SceneTree::initialize(SceneTree * const this) (a:\Recusant\godot\scene\main\scene_tree.cpp:577)
OS_Windows::run(OS_Windows * const this) (a:\Recusant\godot\platform\windows\os_windows.cpp:2328)
widechar_main(int argc, wchar_t ** argv) (a:\Recusant\godot\platform\windows\godot_windows.cpp:96)
_main() (a:\Recusant\godot\platform\windows\godot_windows.cpp:122)
main(int argc, char ** argv) (a:\Recusant\godot\platform\windows\godot_windows.cpp:141)

Steps to reproduce

Simply adding one node as a child of another during _ready of a startup scene can randomly cause this

Minimal reproduction project

recusant.zip

Activity

  1. Ivorforce commented on Nov 23, 2025

    @Ivorforce
    Member

    I think this may be related to previous recent AHashMap related issues, #1873 and #1862.

    We've been trying to track it down, but so far, nobody was able to create a minimal reproduction project for us to reproduce it. Perhaps you could give it a try? That would really help us narrow down the issue to fix it.

  2. added
    bug
    on Nov 23, 2025
  3. Withaust commented on Nov 23, 2025

    @Withaust
    Author

    Sure, I will give it a try. Unfortunatelly this seems to be affected by the count of registered classes (ClassDB::register_class), so I will have to try my best to somehow preserve the segfaulting behaviour while keeping the project size at minumum.

  4. Withaust commented on Nov 23, 2025

    @Withaust
    Author

    @Ivorforce I have attached a MRP to the original post. I've tried my best and this is as "minimal" I could get my project before the segfault went away... It is not pretty to look at. The crash is happening at sources/system/bootstrap.cpp line 210. The thing is, this was my project from Godot 4.3 that I decided to port to 4.5.1, and everything was working on 4.3 previously and port went almost without any issues (besides missing std::vector and std::unordered_map includes that were probably removed down the header dependency tree).

    Image
  5. changed the title [-]`godot::Node->add_child(godot::Node);` segmentation fault[/-] [+]ClassDB AHashMap segmentation fault[/+] on Nov 24, 2025
  6. Withaust commented on Nov 24, 2025

    @Withaust
    Author

    I have tried to debug the issue, but unfortunatelly godot-cpp is really poorly debugabble in VSCode and MinGW even with provided natvis, so I could not figure out what exactly is setting up a faulty state in the ClassInfo::virtual_methods for this to occur. I hope someone else with a better setup debugging environment could take a look at why this is happening.

  7. xana43 commented on Nov 26, 2025

    @xana43

    ah yes this issue. I've done some debugging on this as well, using various tricks to look at the bindings themselves. Both on the GDExtension side and the Godot side. I only know so far that when class registration is started, for whatever reason it does make the map extend to accommodate the new class being registered, but it's in an invalid state. Nothing is out of the ordinary on the Godot side (it's only classes that are registered from GDExtension that has this), and on the GDExtension side, it only sometimes sets up the data correctly. in my also limited debugging of the bindings (I use CLion) there's no indication of the data being corrupted. It gets set up correctly, then suddenly becomes an invalid state when it tries to send it across the bindings (there's more parts of GDExtension that I can't see in the debugger)

    so far the working theory is that it's a race condition or some kind of other undefined behavior as it's not consistent (based on how the compiler decided to compile the whole extension, this issue never arises or it does) even things like the current environment triggers the issue. I hope someone who is more experienced in this can help

  8. enetheru commented on Nov 26, 2025

    @enetheru
    Collaborator

    I beieve this might be helpful #1886

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

    bugcrashplatform:windows

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions