I'm working on a gdextension
. It builds on other libraries that I have made a long time ago. One of those other libraries contains a class called Object
. It is not declared in a namespace.
If in my gdextension
I declare a static ::Object * object {new ::Object {}};
then the godot editor, when opening a project that uses my gdextension
, crashes immediately, typically with malloc(): unaligned tcache chunk detected
or malloc(): invalid size (unsorted)
. Gdb gives this stack trace:
#0 __pthread_kill_implementation (no_tid=0, signo=6, threadid=139933893863424) at ./nptl/pthread_kill.c:44
#1 __pthread_kill_internal (signo=6, threadid=139933893863424) at ./nptl/pthread_kill.c:78
#2 __GI___pthread_kill (threadid=139933893863424, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3 0x00007f44e5e42476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4 0x00007f44e5e287f3 in __GI_abort () at ./stdlib/abort.c:79
#5 0x00007f44e5e896f6 in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7f44e5fdbb8c "%s\n") at ../sysdeps/posix/libc_fatal.c:155
#6 0x00007f44e5ea0d7c in malloc_printerr (str=str@entry=0x7f44e5fdebe0 "malloc(): invalid size (unsorted)") at ./malloc/malloc.c:5664
#7 0x00007f44e5ea415c in _int_malloc (av=av@entry=0x7f44e6019c80 <main_arena>, bytes=bytes@entry=1040) at ./malloc/malloc.c:4002
#8 0x00007f44e5ea6679 in __libc_calloc (n=n@entry=1, elem_size=elem_size@entry=1040) at ./malloc/malloc.c:3679
#9 0x00007f44e5e45792 in __new_exitfn (listp=listp@entry=0x7f44e6019838 <__exit_funcs>) at ./stdlib/cxa_atexit.c:114
#10 0x00007f44e5e4590b in __internal_atexit (listp=0x7f44e6019838 <__exit_funcs>, d=<optimized out>, arg=<optimized out>, func=0x5589ddd81120 <std::ios_base::Init::~Init()>) at ./stdlib/cxa_atexit.c:44
#11 __GI___cxa_atexit (func=0x5589ddd81120 <std::ios_base::Init::~Init()>, arg=<optimized out>, d=<optimized out>) at ./stdlib/cxa_atexit.c:70
#12 0x00007f44e619947e in call_init (l=<optimized out>, argc=argc@entry=4, argv=argv@entry=0x7ffe863ecdb8, env=env@entry=0x7ffe863ecde0) at ./elf/dl-init.c:70
#13 0x00007f44e6199568 in call_init (env=0x7ffe863ecde0, argv=0x7ffe863ecdb8, argc=4, l=<optimized out>) at ./elf/dl-init.c:33
#14 _dl_init (main_map=0x5589e2a086f0, argc=4, argv=0x7ffe863ecdb8, env=0x7ffe863ecde0) at ./elf/dl-init.c:117
#15 0x00007f44e5f74ca5 in __GI__dl_catch_exception (exception=exception@entry=0x0, operate=operate@entry=0x7f44e61a0f40 <call_dl_init>, args=args@entry=0x7ffe863eb500) at ./elf/dl-error-skeleton.c:182
#16 0x00007f44e61a0ff6 in dl_open_worker (a=0x7ffe863eb6a0) at ./elf/dl-open.c:808
#17 dl_open_worker (a=a@entry=0x7ffe863eb6a0) at ./elf/dl-open.c:771
#18 0x00007f44e5f74c48 in __GI__dl_catch_exception (exception=exception@entry=0x7ffe863eb680, operate=operate@entry=0x7f44e61a0f60 <dl_open_worker>, args=args@entry=0x7ffe863eb6a0) at ./elf/dl-error-skeleton.c:208
#19 0x00007f44e61a134e in _dl_open (file=<optimized out>, mode=-2147483646, caller_dlopen=0x5589d9c6c66a <OS_Unix::open_dynamic_library(String, void*&, bool, String*)+652>, nsid=-2, argc=4, argv=<optimized out>, env=0x7ffe863ecde0)
at ./elf/dl-open.c:883
#20 0x00007f44e5e906bc in dlopen_doit (a=a@entry=0x7ffe863eb910) at ./dlfcn/dlopen.c:56
#21 0x00007f44e5f74c48 in __GI__dl_catch_exception (exception=exception@entry=0x7ffe863eb870, operate=<optimized out>, args=<optimized out>) at ./elf/dl-error-skeleton.c:208
#22 0x00007f44e5f74d13 in __GI__dl_catch_error (objname=0x7ffe863eb8c8, errstring=0x7ffe863eb8d0, mallocedp=0x7ffe863eb8c7, operate=<optimized out>, args=<optimized out>) at ./elf/dl-error-skeleton.c:227
#23 0x00007f44e5e901ae in _dlerror_run (operate=operate@entry=0x7f44e5e90660 <dlopen_doit>, args=args@entry=0x7ffe863eb910) at ./dlfcn/dlerror.c:138
#24 0x00007f44e5e90748 in dlopen_implementation (dl_caller=<optimized out>, mode=<optimized out>, file=<optimized out>) at ./dlfcn/dlopen.c:71
#25 ___dlopen (file=<optimized out>, mode=<optimized out>) at ./dlfcn/dlopen.c:81
#26 0x00005589d9c6c66a in OS_Unix::open_dynamic_library (this=0x7ffe863ec7f0, p_path=..., p_library_handle=@0x5589e2a05710: 0x0, p_also_set_library_path=true, r_resolved_path=0x5589e2a05718) at drivers/unix/os_unix.cpp:649
#27 0x00005589dd7f31bf in GDExtension::open_library (this=0x5589e2a05520, p_path=..., p_entry_symbol=...) at core/extension/gdextension.cpp:453
#28 0x00005589dd7f51d0 in GDExtensionResourceLoader::load (this=0x5589e2925350, p_path=..., p_original_path=..., r_error=0x5589e27448cc, p_use_sub_threads=false, r_progress=0x5589e27448c0,
p_cache_mode=ResourceFormatLoader::CACHE_MODE_REUSE) at core/extension/gdextension.cpp:639
#29 0x00005589dd3babdf in ResourceLoader::_load (p_path=..., p_original_path=..., p_type_hint=..., p_cache_mode=ResourceFormatLoader::CACHE_MODE_REUSE, r_error=0x5589e27448cc, p_use_sub_threads=false, r_progress=0x5589e27448c0)
at core/io/resource_loader.cpp:260
#30 0x00005589dd3bb466 in ResourceLoader::_thread_load_function (p_userdata=0x5589e2744878) at core/io/resource_loader.cpp:318
#31 0x00005589dd3bc38f in ResourceLoader::_load_start (p_path=..., p_type_hint=..., p_thread_mode=ResourceLoader::LOAD_THREAD_FROM_CURRENT, p_cache_mode=ResourceFormatLoader::CACHE_MODE_REUSE) at core/io/resource_loader.cpp:497
#32 0x00005589dd3bbd99 in ResourceLoader::load (p_path=..., p_type_hint=..., p_cache_mode=ResourceFormatLoader::CACHE_MODE_REUSE, r_error=0x0) at core/io/resource_loader.cpp:414
#33 0x00005589dd807d51 in GDExtensionManager::load_extension (this=0x5589e28565a0, p_path=...) at core/extension/gdextension_manager.cpp:38
#34 0x00005589dd808760 in GDExtensionManager::load_extensions (this=0x5589e28565a0) at core/extension/gdextension_manager.cpp:142
#35 0x00005589dd1a147a in register_core_extensions () at core/register_core_types.cpp:354
#36 0x00005589d898ef45 in Main::setup (execpath=0x7ffe863ee724 "/home/louise/local/godot/bin/godot.linuxbsd.editor.dev.x86_64", argc=3, argv=0x7ffe863ecdc0, p_second_phase=true) at main/main.cpp:1528
#37 0x00005589d89074a1 in main (argc=4, argv=0x7ffe863ecdb8) at platform/linuxbsd/godot_linuxbsd.cpp:62
When I move the instantiation of the Object
from the static declaration to the _ready()
method of a Node
, then the editor starts up fine, but it crashes when closing. The gdb stack trace is
#0 __pthread_kill_implementation (no_tid=0, signo=6, threadid=139649959467008) at ./nptl/pthread_kill.c:44
#1 __pthread_kill_internal (signo=6, threadid=139649959467008) at ./nptl/pthread_kill.c:78
#2 __GI___pthread_kill (threadid=139649959467008, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3 0x00007f02ca042476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4 0x00007f02ca0287f3 in __GI_abort () at ./stdlib/abort.c:79
#5 0x00005598db45ff35 in handle_crash (sig=11) at platform/linuxbsd/crash_handler_linuxbsd.cpp:141
#6 <signal handler called>
#7 0x00005598dffef031 in Callable::operator== (this=0x5598fac86800, p_callable=...) at core/variant/callable.cpp:226
#8 0x00005598dc10290b in HashMapComparatorDefault<Callable>::compare (p_lhs=..., p_rhs=...) at ./core/templates/hashfuncs.h:398
#9 0x00005598e039ebe4 in HashMap<Callable, Object::SignalData::Slot, HashableHasher<Callable>, HashMapComparatorDefault<Callable>, DefaultTypedAllocator<HashMapElement<Callable, Object::SignalData::Slot> > >::_lookup_pos (
this=0x5598facbb6c8, p_key=..., r_pos=@0x7ffcb38b0124: 0) at ./core/templates/hash_map.h:119
#10 0x00005598e039aa21 in HashMap<Callable, Object::SignalData::Slot, HashableHasher<Callable>, HashMapComparatorDefault<Callable>, DefaultTypedAllocator<HashMapElement<Callable, Object::SignalData::Slot> > >::has (this=0x5598facbb6c8,
p_key=...) at ./core/templates/hash_map.h:310
#11 0x00005598e0390e98 in Object::_disconnect (this=0x5598f2fb7dc0, p_signal=..., p_callable=..., p_force=false) at core/object/object.cpp:1355
#12 0x00005598e03907bf in Object::disconnect (this=0x5598f2fb7dc0, p_signal=..., p_callable=...) at core/object/object.cpp:1338
#13 0x00005598ddea436e in Node::disconnect (this=0x5598f2fb7dc0, p_signal=..., p_callable=...) at scene/main/node.cpp:3611
#14 0x00005598de073e0f in Control::_notification (this=0x5598f2fbcb10, p_notification=33) at scene/gui/control.cpp:3183
#15 0x00005598dbeab5f6 in Control::_notificationv (this=0x5598f2fbcb10, p_notification=33, p_reversed=true) at ./scene/gui/control.h:47
#16 0x00005598dcf1d9cb in BaseButton::_notificationv (this=0x5598f2fbcb10, p_notification=33, p_reversed=true) at ./scene/gui/base_button.h:40
#17 0x00005598dcf1e385 in Button::_notificationv (this=0x5598f2fbcb10, p_notification=33, p_reversed=true) at ./scene/gui/button.h:38
#18 0x00005598e038bd11 in Object::notification (this=0x5598f2fbcb10, p_notification=33, p_reversed=true) at core/object/object.cpp:796
#19 0x00005598dddfea66 in CanvasItem::_exit_canvas (this=0x5598f2fbcb10) at scene/main/canvas_item.cpp:270
#20 0x00005598dddff3d8 in CanvasItem::_notification (this=0x5598f2fbcb10, p_what=11) at scene/main/canvas_item.cpp:347
#21 0x00005598dbeaac10 in CanvasItem::_notificationv (this=0x5598f2fbcb10, p_notification=11, p_reversed=true) at ./scene/main/canvas_item.h:45
#22 0x00005598dbeab611 in Control::_notificationv (this=0x5598f2fbcb10, p_notification=11, p_reversed=true) at ./scene/gui/control.h:47
#23 0x00005598dcf1d9cb in BaseButton::_notificationv (this=0x5598f2fbcb10, p_notification=11, p_reversed=true) at ./scene/gui/base_button.h:40
#24 0x00005598dcf1e385 in Button::_notificationv (this=0x5598f2fbcb10, p_notification=11, p_reversed=true) at scene/gui/button.h:38
#25 0x00005598e038bd11 in Object::notification (this=0x5598f2fbcb10, p_notification=11, p_reversed=true) at core/object/object.cpp:796
#26 0x00005598dde815f5 in Node::_propagate_exit_tree (this=0x5598f2fbcb10) at scene/main/node.cpp:339
#27 0x00005598dde81586 in Node::_propagate_exit_tree (this=0x5598f2fb7dc0) at scene/main/node.cpp:330
#28 0x00005598dde81586 in Node::_propagate_exit_tree (this=0x5598f2fcb610) at scene/main/node.cpp:330
#29 0x00005598dde81586 in Node::_propagate_exit_tree (this=0x5598f2dea740) at scene/main/node.cpp:330
#30 0x00005598dde81586 in Node::_propagate_exit_tree (this=0x5598f2c4d620) at scene/main/node.cpp:330
#31 0x00005598dde81586 in Node::_propagate_exit_tree (this=0x5598f2c46a40) at scene/main/node.cpp:330
#32 0x00005598dde81586 in Node::_propagate_exit_tree (this=0x5598f27d0160) at scene/main/node.cpp:330
#33 0x00005598dde81586 in Node::_propagate_exit_tree (this=0x5598ea5b6c50) at scene/main/node.cpp:330
#34 0x00005598dde81586 in Node::_propagate_exit_tree (this=0x5598ea5adbf0) at scene/main/node.cpp:330
#35 0x00005598dde81586 in Node::_propagate_exit_tree (this=0x5598ea51ed60) at scene/main/node.cpp:330
#36 0x00005598dde81586 in Node::_propagate_exit_tree (this=0x5598ea51b2a0) at scene/main/node.cpp:330
#37 0x00005598dde81586 in Node::_propagate_exit_tree (this=0x5598ea4cb3c0) at scene/main/node.cpp:330
#38 0x00005598dde81586 in Node::_propagate_exit_tree (this=0x5598ea4c98d0) at scene/main/node.cpp:330
#39 0x00005598dde81586 in Node::_propagate_exit_tree (this=0x5598ea4c5fc0) at scene/main/node.cpp:330
#40 0x00005598dde81586 in Node::_propagate_exit_tree (this=0x5598ea4af560) at scene/main/node.cpp:330
#41 0x00005598dde81586 in Node::_propagate_exit_tree (this=0x5598ea498bd0) at scene/main/node.cpp:330
#42 0x00005598dde81586 in Node::_propagate_exit_tree (this=0x5598ea495690) at scene/main/node.cpp:330
#43 0x00005598dde81586 in Node::_propagate_exit_tree (this=0x5598ea483ae0) at scene/main/node.cpp:330
#44 0x00005598dde81586 in Node::_propagate_exit_tree (this=0x5598ea482ee0) at scene/main/node.cpp:330
#45 0x00005598dde81586 in Node::_propagate_exit_tree (this=0x5598e85990c0) at scene/main/node.cpp:330
#46 0x00005598dde81586 in Node::_propagate_exit_tree (this=0x5598e852bed0) at scene/main/node.cpp:330
#47 0x00005598dde93862 in Node::_set_tree (this=0x5598e852bed0, p_tree=0x0) at scene/main/node.cpp:2894
#48 0x00005598dded1204 in SceneTree::finalize (this=0x5598e852b9e0) at scene/main/scene_tree.cpp:626
#49 0x00005598db468f28 in OS_LinuxBSD::run (this=0x7ffcb38b1100) at platform/linuxbsd/os_linuxbsd.cpp:917
#50 0x00005598db45f508 in main (argc=4, argv=0x7ffcb38b16c8) at platform/linuxbsd/godot_linuxbsd.cpp:74
I have done numerous tests, and I hardly dare say this, but it is as if the name of the class is the issue. If I create a copy of the class and rename it to e.g. X
, then the editor starts just fine.
Any help is appreciated.