Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CharString variable declaration in GDNative code causes crash when that method is called from GDScript #66846

Open
todd-koeck opened this issue Oct 3, 2022 · 2 comments

Comments

@todd-koeck
Copy link

todd-koeck commented Oct 3, 2022

Godot version

3.5.1.stable

System information

WIndows 10

Issue description

When a CharString variable is declared in a C++ method called by GDScript, Godot will crash shortly after, possibly during, the return from the called C++ method.

I think this was crashing under linux as well, but most of my testing and debugging of this crash was performed under windoze.

I ran into the problem on another project where I was initially using a CharString to convert a Godot::String to a C/C++ string before I found String::alloc_c_string(). However, I left the CharString declaration in that code and was getting random crashes on the first call, unless I had a print() statement immediately before it in the calling GDScript code. Once I removed the declaration of the unused CharString variable, the crashes stopped.

To verify that removing the CharString variable declaration was really a fix, I added one to the GDNative C++ Example code. That code now crashes as well.

Steps to reproduce

Start with the GDExample class in the GDNative C++ Example tutorial. Declare a CharString variable in the _process() method:

void GDExample::_process(float delta) {
  CharString cs;                          // <------- Added this line
  time_passed += speed * delta;

  Vector2 new_position = Vector2(
				 (real_t) (amplitude + (amplitude * sin(time_passed * 2.0))),
				 (real_t) (amplitude + (amplitude * cos(time_passed * 1.5)))
				 );

  set_position(new_position);
}

Build the code.

Run the main.tscn scene.

It should crash.

Minimal reproduction project

GDNative C++ Example

@todd-koeck
Copy link
Author

The GDNative C++ Example crashes under linux (debian 11.3) as well. However, I get a backtrace there, which I didn't when it crashed under windoze.

================================================================
handle_crash: Program crashed with signal 11
Engine version: Godot Engine v3.5.1.stable.official (6fed1ffa313c6760fa88b368ae580378daaef0f0)
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(+0x3bd60) [0x7fc1e4717d60] (??:0)
[2] .../Godot_v3.5.1-stable_x11.64() [0x10dbfb8] (??:0)
[3] godot::CharString::~CharString() (??:0)
[4] godot::GDExample::_process(float) (??:0)
[5] godot_variant godot::__wrapped_method<godot::GDExample, void, float>(void*, void*, void*, int, godot_variant**) (??:0)
[6] .../Godot_v3.5.1-stable_x11.64() [0xed8298] (??:0)
[7] .../Godot_v3.5.1-stable_x11.64() [0x1f835ef] (??:0)
[8] .../Godot_v3.5.1-stable_x11.64() [0x24bc7d0] (??:0)
[9] .../Godot_v3.5.1-stable_x11.64() [0x1fad99e] (??:0)
[10] .../Godot_v3.5.1-stable_x11.64() [0x1fe3429] (??:0)
[11] .../Godot_v3.5.1-stable_x11.64() [0xa91d0a] (??:0)
[12] .../Godot_v3.5.1-stable_x11.64() [0xa0240d] (??:0)
[13] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xea) [0x7fc1e4702d0a] (??:0)
[14] .../Godot_v3.5.1-stable_x11.64() [0xa14e0e] (??:0)
-- END OF BACKTRACE --
================================================================

@Zylann
Copy link
Contributor

Zylann commented Oct 3, 2022

Note: godotengine/godot-cpp#842

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants