Skip to content

Using input method causes game to crash #257

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

Closed
LordCocoNut opened this issue May 3, 2023 · 4 comments · Fixed by #275
Closed

Using input method causes game to crash #257

LordCocoNut opened this issue May 3, 2023 · 4 comments · Fixed by #275
Labels
bug c: ffi Low-level components and interaction with GDExtension API ub Undefined behavior

Comments

@LordCocoNut
Copy link

LordCocoNut commented May 3, 2023

I'm using an input method of the godot-api for a custom Npc class like so:

#[godot_api]
impl CharacterBody3DVirtual for Npc {
   ...
    fn input(&mut self, event: Gd<InputEvent>) {
   }
}

When i have gamepad connected to the pc (probably cause of joypad continuous input) and i run the game from the editor, the game randomly crashes after few seconds when triggering input via keyboard or mouse. Disconnecting the gamepad from pc solves the problem.

Trace log doesn't show any interesting stuff, these are few input records from terminal before crashing

Gd::drop   <godot_core::gen::classes::input::re_export::Input>
Gd::drop   <godot_core::gen::classes::input_event::re_export::InputEvent>
  Stat::dec   <godot_core::gen::classes::input_event::re_export::InputEvent>
  +-- was last=false
ptrcall: input
Gd::drop   <godot_core::gen::classes::input::re_export::Input>
Gd::drop   <godot_core::gen::classes::input_event::re_export::InputEvent>
  Stat::dec   <godot_core::gen::classes::input_event::re_export::InputEvent>
  +-- was last=false

The crash itself looks like so:

handle_crash: Program crashed with signal 11
Engine version: Godot Engine v4.1.dev1.official (db1302637023168f7becceb1c4ce13228e1b2a43)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[1] /lib/x86_64-linux-gnu/libc.so.6(+0x42520) [0x7f91fee42520] (??:0)
[2] /home/bonsai/GameDev/godot/godot4() [0x468ca27] (??:0)
[3] /home/bonsai/GameDev/godot/godot4() [0x45dbc1c] (??:0)
[4] /home/bonsai/GameDev/godot/godot4() [0x43a9493] (??:0)
[5] /home/bonsai/GameDev/godot/godot4() [0xe59641] (??:0)
[6] /home/bonsai/GameDev/godot/godot4() [0xe5df5a] (??:0)
[7] /home/bonsai/GameDev/godot/godot4() [0xde4090] (??:0)
[8] /lib/x86_64-linux-gnu/libc.so.6(+0x29d90) [0x7f91fee29d90] (??:0)
[9] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x7f91fee29e40] (??:0)
[10] /home/bonsai/GameDev/godot/godot4() [0xdf1f7e] (??:0)
-- END OF BACKTRACE --

The problem doesnt seem to happen when i

  • disconnect gamepad from pc
  • not using mouse or keyboard while gamepad connected (i can press anything on the gamepad tho)

@lilizoey suggested using std::mem::forget(event) at the end of the input method, which seems to solve the problem aswell. This little amnesia allows me to run the game without any issue. That led to the conclusion, that it might be wrong handling of a reference count

Ive been also asked to reference the issue #204 as it might be related.

@lilizoey lilizoey added bug c: ffi Low-level components and interaction with GDExtension API labels May 3, 2023
@Bromeon
Copy link
Member

Bromeon commented May 3, 2023

Can you reproduce the same behavior with GDScript, or does it happen only in Rust?

@LordCocoNut
Copy link
Author

Im using gdscript _inputs without any issues. The problem comes up only when i add the input method in some rust implementation and use it in the game. The input method as provided in the example can also be empty and the issue still happens.

@KameiKojirou
Copy link

does adding this to Cargo.toml make it work?

[patch."https://github.com/godot-rust/godot4-prebuilt"] godot4-prebuilt = { git = "https://github.com//godot-rust/godot4-prebuilt", branch = "4.0.2"}

@LordCocoNut
Copy link
Author

@KameiKojirou no effect at all

@bors bors bot closed this as completed in 7dbd80f May 25, 2023
@Bromeon Bromeon added the ub Undefined behavior label Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug c: ffi Low-level components and interaction with GDExtension API ub Undefined behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants