gdext icon indicating copy to clipboard operation
gdext copied to clipboard

Crash when using can_drop_data

Open DSOverlord opened this issue 1 year ago • 4 comments

I have the game crashing in almost any scenario using drop_data. Even with something as simple as this:

    fn get_drag_data(&mut self, _at_position: Vector2) -> Variant {
        let drag_data = "test".to_variant();
        return drag_data;
    }
    fn can_drop_data(&self, _at_position: Vector2, data: Variant) -> bool {
        godot_print!("{:?}", data);
        return false;
    }

Am I doing something wrong, or is this a bug?

DSOverlord avatar Sep 03 '23 17:09 DSOverlord

Do you get any error messages? Either in godot or if you could try running godot from the terminal/command line and see if you get any error messages there?

lilizoey avatar Sep 03 '23 17:09 lilizoey

Here are all the messages I'm getting:

Variant(ty=String, val=test)
Variant(ty=String, val=)
Variant(ty=String, val=)
Variant(ty=String, val=)
thread '<unnamed>' panicked at 'GodotString::chars_checked: string contains invalid unicode scalar values', /home/dsoverlord/.cargo/git/checkouts/gdext-76630c89719e160c/2b6fce2/godot-core/src/builtin/string/godot_string.rs:66:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5

DSOverlord avatar Sep 03 '23 17:09 DSOverlord

i can reproduce this at least, so it does seem like a bug, not entirely sure why it's happening though

lilizoey avatar Sep 03 '23 17:09 lilizoey

@lilizoey @DSOverlord I think I had the same issue, see:

https://discord.com/channels/723850269347283004/1190796227235823647

I wonder if the issue is that nothing owns the variant so its memory gets freed in the meantime somehow? I tried in my example to store the object (in my case an array and in yours a string) in the Control node which seems to avoid the crash but it still doesn't pass the correct array to drop_data. See more details in the above discord thread.

AckslD avatar Dec 31 '23 20:12 AckslD

@DSOverlord @AckslD there have been some FFI improvements/fixes in the meantime, can you still reproduce this issue?

(Well possible that yes, just want to make sure we're not tracking outdated tasks :wink: )

Bromeon avatar Jun 12 '24 17:06 Bromeon

@Bromeon the crashes I was reproducing in this small example repo now indeed seem fixed and it does not crash anymore :rocket: So from my part this can be closed.

AckslD avatar Jun 13 '24 02:06 AckslD

I also tested on my example and the glitches are fixed. So I think this issue can be closed.

DSOverlord avatar Jun 13 '24 08:06 DSOverlord