godot icon indicating copy to clipboard operation
godot copied to clipboard

'Program crashed with signal 11' on manually linking GDExtension library to project

Open laingawbl opened this issue 2 years ago • 6 comments

Godot version

v4.0.alpha6.official (e4f0fc50f)

System information

Linux (Ubuntu Jammy), Vulkan Clustered

Issue description

I have a GDExtension library, say libcrashexample. I have compiled it via scons against godot-cpp@0b05044, and now it's in my project directory under res://bin/x11. Then, creating a .gdextension file referring to that library (as suggested in the post announcing GDExtension) causes Godot 4.0.alpha6 to crash on loading [my uname scrubbed :) ]:

Editing project: /home/████/Desktop/crash-example (::home::████::Desktop::crash-example)
ERROR: Index p_type_a = 1228648128 is out of bounds (Variant::VARIANT_MAX = 35).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:913)
ERROR: Index p_type_b = 1228648640 is out of bounds (Variant::VARIANT_MAX = 35).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:914)
ERROR: Index p_type_b = 1228648640 is out of bounds (Variant::VARIANT_MAX = 35).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:914)
ERROR: Index p_type_b = 1228648640 is out of bounds (Variant::VARIANT_MAX = 35).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:914)
ERROR: Index p_type_b = 1228648640 is out of bounds (Variant::VARIANT_MAX = 35).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:914)
ERROR: Index p_type_b = 1228648640 is out of bounds (Variant::VARIANT_MAX = 35).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:914)
ERROR: Index p_type_b = 1228648640 is out of bounds (Variant::VARIANT_MAX = 35).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:914)
ERROR: Index p_type_b = 1228648640 is out of bounds (Variant::VARIANT_MAX = 35).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:914)
ERROR: Index p_type_b = 1228648640 is out of bounds (Variant::VARIANT_MAX = 35).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:914)
ERROR: Index p_type_b = 1228648640 is out of bounds (Variant::VARIANT_MAX = 35).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:914)
ERROR: Index p_type_b = 1228648640 is out of bounds (Variant::VARIANT_MAX = 35).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:914)
ERROR: Index p_type_b = 1228648640 is out of bounds (Variant::VARIANT_MAX = 35).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:914)
ERROR: Index p_type_b = 1228648640 is out of bounds (Variant::VARIANT_MAX = 35).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:914)
ERROR: Index p_type_b = 1228648640 is out of bounds (Variant::VARIANT_MAX = 35).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:914)
ERROR: Index p_type_b = 1228648640 is out of bounds (Variant::VARIANT_MAX = 35).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:914)
ERROR: Index p_type_b = 1228648640 is out of bounds (Variant::VARIANT_MAX = 35).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:914)
ERROR: Index p_type_b = 1228648640 is out of bounds (Variant::VARIANT_MAX = 35).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:914)
ERROR: Index p_type_b = 1228648640 is out of bounds (Variant::VARIANT_MAX = 35).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:914)
ERROR: Index p_type_b = 1228648640 is out of bounds (Variant::VARIANT_MAX = 35).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:914)
ERROR: Index p_type_b = 1228648640 is out of bounds (Variant::VARIANT_MAX = 35).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:914)
ERROR: Index p_type_b = 1228648640 is out of bounds (Variant::VARIANT_MAX = 35).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:914)
ERROR: Index p_type_b = 1228648640 is out of bounds (Variant::VARIANT_MAX = 35).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:914)
ERROR: Index p_type_b = 1228648640 is out of bounds (Variant::VARIANT_MAX = 35).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:914)
ERROR: Index p_operator = 24 is out of bounds (Variant::OP_MAX = 24).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:912)
ERROR: Index p_operator = 25 is out of bounds (Variant::OP_MAX = 24).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:912)
ERROR: Index p_operator = 26 is out of bounds (Variant::OP_MAX = 24).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:912)
ERROR: Index p_operator = 27 is out of bounds (Variant::OP_MAX = 24).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:912)
ERROR: Index p_operator = 28 is out of bounds (Variant::OP_MAX = 24).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:912)
ERROR: Index p_operator = 29 is out of bounds (Variant::OP_MAX = 24).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:912)
ERROR: Index p_operator = 30 is out of bounds (Variant::OP_MAX = 24).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:912)
ERROR: Index p_operator = 31 is out of bounds (Variant::OP_MAX = 24).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:912)
ERROR: Index p_operator = 32 is out of bounds (Variant::OP_MAX = 24).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:912)
ERROR: Index p_operator = 33 is out of bounds (Variant::OP_MAX = 24).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:912)
ERROR: Index p_operator = 34 is out of bounds (Variant::OP_MAX = 24).
   at: get_ptr_operator_evaluator (core/variant/variant_op.cpp:912)

================================================================
handle_crash: Program crashed with signal 11
Engine version: Godot Engine v4.0.alpha6.official (e4f0fc50f79336cf76beec40e5e8e5164b288714)
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[1] /lib/x86_64-linux-gnu/libc.so.6(+0x42520) [0x7f584ae93520] (??:0)
[2] /home/████/Desktop/Godot_v4.0-alpha6_linux.64() [0x3fd7a9c] (??:0)
[3] godot::String::init_bindings() (??:0)
[4] godot::Variant::init_bindings() (??:0)
[5] godot::GDExtensionBinding::init(GDNativeInterface const*, void*, GDNativeInitialization*) (??:0)
[6] godot::GDExtensionBinding::InitObject::init() const (??:0)
[7] /home/████/Desktop/crash-example/bin/x11/libcrashexample.linux.debug.so(crash_example_library_init+0x50) [0x7f58493832b8] (??:0)
[8] /home/████/Desktop/Godot_v4.0-alpha6_linux.64() [0x3f375c3] (??:0)
[9] /home/████/Desktop/Godot_v4.0-alpha6_linux.64() [0x3fb82ec] (??:0)
[10] /home/████/Desktop/Godot_v4.0-alpha6_linux.64() [0x3d4d5f4] (??:0)
[11] /home/████/Desktop/Godot_v4.0-alpha6_linux.64() [0x3d4db19] (??:0)
[12] /home/████/Desktop/Godot_v4.0-alpha6_linux.64() [0x3d6ea22] (??:0)
[13] /home/████/Desktop/Godot_v4.0-alpha6_linux.64() [0x3f45aa9] (??:0)
[14] /home/████/Desktop/Godot_v4.0-alpha6_linux.64() [0xd3d07c] (??:0)
[15] /lib/x86_64-linux-gnu/libc.so.6(+0x29d90) [0x7f584ae7ad90] (??:0)
[16] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x7f584ae7ae40] (??:0)
[17] /home/████/Desktop/Godot_v4.0-alpha6_linux.64() [0xd55fde] (??:0)
-- END OF BACKTRACE --
================================================================
  • I created the .gdextension file using a text editor. When I go to the "New Resource" creator in the editor and select "NativeExtension", I don't see any interface to edit the extension or point it at libraries for various platforms, as there was for GDNative, so I thought manual editing was the only way to link a GDExtension at this alpha.
  • Is my problem maybe because godot-cpp@0b05044 is for 4.0-alpha7? That commit's message says headers: Sync with upstream commit 3e9ead0 (4.0-alpha7). Should I have checked out and built against an earlier commit?
  • I can supply the C++ sources of libcrashexample if you want to see it.

Steps to reproduce

  1. Open the minimal reproduction project in Godot 4.0-alpha6. See it's fine. There's nothing but a single scene with a Node3d in the project.
  2. See that bin/x11/libcrashexample.linux.debug.so exists in the project files.
  3. Manually create some .gdextension file in the project, with the following contents:
[configuration]

entry_symbol = "crash_example_library_init"

[libraries]

linux.64 = "bin/x11/libcrashexample.linux.debug.so"
  1. Open the project in Godot again. See it crashes with a backtrace similar to the one above.

Minimal reproduction project

crash-example.zip

laingawbl avatar May 03 '22 20:05 laingawbl

I'd like to add that the entry symbol looks like this (includes omitted):

using namespace godot;

void register_crash_example_types() {
  ClassDB::register_class<foo::CrashExample>();
}

void unregister_crash_example_types() {}

extern "C" {

// Initialization.

GDNativeBool GDN_EXPORT
crash_example_library_init(const GDNativeInterface *p_interface,
                           const GDNativeExtensionClassLibraryPtr p_library,
                           GDNativeInitialization *r_initialization) {
  godot::GDExtensionBinding::InitObject init_obj(p_interface, p_library,
                                                 r_initialization);

  init_obj.register_scene_initializer(register_crash_example_types);
  init_obj.register_scene_terminator(unregister_crash_example_types);

  return init_obj.init();
}
}

If I get rid of register_scene_{initializer,terminator}(...); in crash_example_library_init so the function body is just

...(...) {
  return init_obj.init();
}

Godot doesn't crash.

laingawbl avatar May 03 '22 20:05 laingawbl

Any news on why this happens?

laingawbl avatar Aug 04 '22 22:08 laingawbl

I encountered the same problem in my GDExtension project. This commit includes everything I did for fixing it and getting it running: https://github.com/boku-ilen/geodot-plugin/commit/eb1686afcac8d354e377ec1ae68a468149b0f8e2

I believe it was caused by linking to an old godot-cpp state. Multiple changes were needed to fix this:

  • Update the godot-cpp submodule to the latest master
  • Add the '.x86_' prefix to the binary linked against in the SConstruct script (it seems like this was renamed in godot-cpp, so without this change, the old binary is linked against!)
  • Modify register_types.cpp according to the new API, e.g. register_initializer rather than register_scene_initializer

That last point is probably why it works when you get rid of those calls - I believe it's a mis-match between two GDExtension API versions (the one linked in your GDExtension project vs. the one in your Godot 4.0 alpha executable)

All of these changes can be seen in practice in the commit I linked above. Hopefully this helps you or anyone else stumbling across this issue (like I did a few hours ago :P)

kb173 avatar Sep 14 '22 20:09 kb173

I also had this problem but it seems to have been solved in Godot's 4 beta 2.

98teg avatar Sep 30 '22 18:09 98teg

Running into this problem again with Godot 4.0 Beta 3 - were there any major new API changes that can cause this again?

I saw that the suffix changed from e.g. debug.x86_64.a to template_debug.x86_64.a, but adapting that didn't fix it. (Seems like the suffix can be imported from godot-cpp's SConstruct script, which might be a good idea)

Edit: nevermind, that did fix it - the error was coming from a different GDExtension.

Perhaps it's possible to somehow catch this type of error (e.g. by writing the version which the GDExtension was compiled for somewhere and checking against it) and give a clearer message to the user?

kb173 avatar Oct 14 '22 16:10 kb173

I ran into this issue as well, my fix was to checkout the latest version of master for both godot-cpp and godot itself, then compile godot and use that godot binary to run the editor with my GDExtension

jrenner avatar Nov 28 '22 01:11 jrenner

Seems like this issue was potentially having multiple reports of issues caused either by running godot-cpp out of sync with godot, or using the wrong version of the library due to some pre-4.0 suffix changes.

I assume this is solved by now when using 4.0.3-stable for both projects, or the commits labeled for e.g. 4.1-beta3.

akien-mga avatar Jun 23 '23 12:06 akien-mga