Godot crashes with "Node not found" error when attempting to add a GDExtension class to Godot project

Godot Version

4.5

Question

Hi everyone, I am currently trying to get J-Dax’s Godot 4.3 C++ code for the Your First 2D Game Tutorial to work within Version 4.5 of Godot. (My project code can be found here. I compiled it with Version 4.5 of the godot-cpp code.) I’d eventually like to use his code to create 4.5-compatible C++ snippets that will be equivalent to the GDScript and C# snippets in the existing documentation.

So far, I’ve added in some C++ code for the Coding the Player scene. I’m able to see the new Player class that was created within my GDExtension script; however, when I attempt to add this class to my project, Godot crashes with the following error:

ERROR: Node not found: "AnimatedSprite2D" (relative to "/root/@EditorNode@20438/@Panel@14/@VBoxContainer@15/DockHSplitLeftL/DockHSplitLeftR/DockHSplitMain/@VBoxContainer@26/DockVSplitCenter/@VSplitContainer@62/@VBoxContainer@63/@EditorMainScreen@103/MainScreen/@CanvasItemEditor@10871/@VSplitContainer@10516/@HSplitContainer@10518/@HSplitContainer@10520/@Control@10521/@SubViewportContainer@10522/@SubViewport@10523/Player/Player").

Interestingly, when I downloaded, compiled, and launched J-Dax’s own 4.3 project, a similar error occurred when I tried to add his Player to the scene–even though the game itself ran fine.

I did not encounter this issue with the ‘Getting started’ GDExtension example; I was able to add a GDExample node to my scene for that project without any trouble.

I imagine I might be overlooking something obvious. Any help with debugging this would be greatly appreciated! If it’s relevant, I’m using Godot 4.5 with Linux Mint and an x86-64 processor.

PS: Here’s the backtrace from when the program crashed:

================================================================
handle_crash: Program crashed with signal 11
Engine version: Godot Engine v4.5.stable.official (876b290332ec6f2e6d173d08162a02aa7e6ca46d)
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(+0x45330) [0x7a7c76c45330] (??:0)
[2] /home/kjb3/D1V1/kjb3largefiles/large_programming/godot_cpp_games/cpp_yf2dg/project/bin/libexample.linux.template_debug.x86_64.so(+0xdac59) [0x7a7c684dac59] (??:0)
[3] /home/kjb3/D1V1/kjb3largefiles/large_programming/godot_cpp_games/cpp_yf2dg/project/bin/libexample.linux.template_debug.x86_64.so(+0xa0808) [0x7a7c684a0808] (??:0)
[4] /home/kjb3/Applications/Godot_v4.5-stable_linux.x86_64() [0x2871ca1] (??:0)
[5] /home/kjb3/Applications/Godot_v4.5-stable_linux.x86_64() [0x30e1ded] (??:0)
[6] /home/kjb3/Applications/Godot_v4.5-stable_linux.x86_64() [0x47baf91] (??:0)
[7] /home/kjb3/Applications/Godot_v4.5-stable_linux.x86_64() [0x2866fd5] (??:0)
[8] /home/kjb3/Applications/Godot_v4.5-stable_linux.x86_64() [0x286816f] (??:0)
[9] /home/kjb3/Applications/Godot_v4.5-stable_linux.x86_64() [0x286da61] (??:0)
[10] /home/kjb3/Applications/Godot_v4.5-stable_linux.x86_64() [0x53e529] (??:0)
[11] /home/kjb3/Applications/Godot_v4.5-stable_linux.x86_64() [0x42d2b7] (??:0)
[12] /lib/x86_64-linux-gnu/libc.so.6(+0x2a1ca) [0x7a7c76c2a1ca] (??:0)
[13] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x8b) [0x7a7c76c2a28b] (??:0)
[14] /home/kjb3/Applications/Godot_v4.5-stable_linux.x86_64() [0x46cb7a] (??:0)
-- END OF C++ BACKTRACE --

So the crash happens when you add the Player from your GDExtension to another Node in the editor?

I think it happened whenever I tried to add my GDExtension to the scene tree (if that’s the right term), either by changing an existing node or by adding it as a new node.

Thankfully, after quite a bit of trial and error, I was able to get it figured out. The issue was that I was using register_types.cpp and register_types.h code files written for version 4.3. Something about these files was evidently incompatible with version 4.5. When I replaced them with corresponding version 4.5 files from the C++ GDExtension documentation, I was able to successfully import my Player node.

I’ve updated my GitHub repository accordingly.

1 Like