godotengine / godot-cpp

C++ bindings for the Godot script API
MIT License
1.66k stars 502 forks source link

[GDNative] Godot::print and String() randomly change the input char* #829

Open 2shady4u opened 2 years ago

2shady4u commented 2 years ago

Both the Godot::print(const char*) and String(const char*)-methods randomly change the content of their input const char*.

Here's a minimal reproduction method:

void SQLite::test(String input)
{
    const CharString dummy_input = input.utf8();
    const char *char_input = dummy_input.get_data();

    std::cout << char_input << std::endl;

    Godot::print(char_input);

    std::cout << char_input << std::endl;
}

Code in Godot itself:

func _ready() -> void:
    db = SQLite.new()
    db.test("I love GDNative!")

Which prints in the console:

I love GDNative!
I love GDNative!
I love GDNative!

or

I love GDNative!
I love GDNative!
I

or

I love GDNative!
I love GDNative!
 ▐↕▬

or other similar random junk

Why is this happening? Am I not allowed to use char_input anymore after I print it?

2shady4u commented 2 years ago

Might be related? https://github.com/godotengine/godot/issues/40957