Closed Im-Oab closed 3 years ago
This issue also appears in the tetra example/gamepad.
cargo run --example gamepad
Esc
for closing.cargo run --example gamepad
again. It should throw an error message.😬 noooooo
I feel like this is likely to be an issue in sdl2-rs or SDL2 itself - the only way you can get segmentation faults in Rust is via unsafe code, and I don't have any unsafe code involving gamepads as far as I can remember. Do you happen to know which version of SDL your game is using? If it's an old-ish one, I'd be interested to know if upgrading fixes this.
If that doesn't help, I will try to do some investigation over the weekend.
Just confirmed that there's only three places with unsafe
in Tetra:
mesh.rs
uses unsafe to tell bytemuck
that the Vertex
type is safe to turn into bytes.device_gl.rs
uses unsafe to interact with the OpenGL bindings.window_sdl.rs
uses unsafe to create the OpenGL context.There is no unsafety anywhere relating to gamepads, so unless I've triggered some weird ripple-effect UB with one of the above bits of code, this has to be unsoundness somewhere in sdl2-rs. I will see if I can narrow it down further, and if I can find the cause I will file an upstream bug report.
I haven't been able to replicate this yet as my only other controllers are joysticks/steering wheels, and SDL does not register them as gamepads.
I have pushed a branch with some debug statements added, to try to see where during startup the segfault is happening - could you try with this dependency and let me know what it prints @Im-Oab?
tetra = { git = "https://github.com/17cupsofcoffee/tetra", branch = "gamepad-debug" }
This is my SDL2 version.
and I set up a new project, copy the examples
folder from gamepad-debug
branch. I got this message after call cargo run --example gamepad
Ah, that's an unrelated issue - tetra 0.6.5 added some code that uses const generics, which were added to stable Rust in March. Running rustup update
should make that error go away, but in case you need to stay on an old version for whatever reason, I've pushed a commit to the branch to comment that code out.
The SDL version looks fine to me - 2.0.14 is only one release behind the latest (and I haven't updated to the latest yet either).
After I did rustup update
. the error gone.
The segmentation fault
error change after I called cargo run --example gamepad
again and again.
That's extremely strange, it's crashing right at startup by the looks of it - which is before we actually do anything with the controllers themselves... I have a feeling this might be an SDL2 bug.
Just out of interest, are you always plugging the gamepads in the same order? I wonder if it's something to do with SDL not playing nice with one of those controllers in particular.
I will try to see if I can get my steering wheel controller to be picked up by SDL, just remembered it has a PS4 mode that might make it register as a gamepad...
Yes. It is the same order when i try to reproduce the bug.
I just found this patch on the SDL2 issue tracker that looks like it could be relevant, given that it mentions Macs, multiple gamepads and an 8BitDo controller: https://github.com/libsdl-org/SDL/commit/bdc6e4ffc5db34940b11bb63e2379bcf194ed990
That bug was fixed in 2.0.16, which is one release newer than the one you've got now. Could you try updating your SDL version via Homebrew and doing a clean build? Hopefully that'll fix your issue 🤞
Even if it doesn't, I'm fairly convinced this error must be coming from SDL2 rather than the Rust bindings or Tetra, as it's happening so early in initialization.
Thanks you. The error is gone after I updated it to 2.0.16.
No problem, thanks for the help debugging this :)
Summary
My game randomly crashes at the start of the runtime with the error message
Segmentation fault: 11
and this error appear when 2 gamepads connected with the computer before running the game usingcargo run
error message after call
cargo run
main function. I printing
start main
message when it start.GameState::new(). It should called from
main()
with printing messagemain::new
at start of the function.From the printing message. I assume that the game crash before entering
GameState::new()
Steps to Reproduce
cargo run
get_gamepad_name()
,get_gamepad_axis_position()
,is_key_down()
,is_gamepad_button_down()
Esc
cargo run
again. The error should appear. If it not appear try it again 2 or 3 times.Additional Info
OSX Catalina 10.15.7 tetra = "0.6.2" gamepads: