cemu-project / Cemu

Cemu - Wii U emulator
https://cemu.info
Mozilla Public License 2.0
7.37k stars 604 forks source link

[Linux] Rapid SDL Controller Reconnects Can Crash Cemu #918

Open ThisNekoGuy opened 1 year ago

ThisNekoGuy commented 1 year ago

2200cc0ddf61d345c774daccdbadd92a00133890

backtrace.log log.txt

I had Cemu crash while I was playing the other day but didn't quite know how to reproduce it since it kind of just seemed to happen spontaneously, so I decided to start running Cemu with GDB until I could get it to happen again and see what it could have been.

It seems as though the issue is that Cemu doesn't always handle rapid SDL controller disconnects and reconnects and it crashes by throwing an assertion when defining an array related to motion sensor information:

/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.1.1/../../../../include/c++/13.1.1/array:202:
std::array::reference std::array<SDLControllerProvider::MotionInfoTracking, 8>::operator[](std::array::size_type) [_Tp = SDLControllerProvider::MotionInfoTracking, _Nm = 8]: Assertion '__n < this->size()' failed.

In context for when this happens for me, I was charging a PS4 controller (which has a motion sensor) with a slightly loose cable (because I lost the original cable it came with) and Cemu either stutters when it wiggles out of place and reconnects quickly or crashes as a result regardless if motion controls are disabled in the controller configuration.

Other Information:

tavlima commented 1 year ago

I'm facing similar issues with the ARM macOS as well. My PS4 controller seems to be randomly disconnecting, sometimes changing the light from blue to red (sounds like https://github.com/RPCS3/rpcs3/issues/12290, but I'm not sure) and connecting it again sometimes triggers the crash.

sweetgiorni commented 8 hours ago

I can consistently reproduce this Windows with an 8BitDo Pro 2 BT controller by reconnecting the controller eight times. These arrays are hard-coded to have a length of eight, but they're indexed with the joystick instance ID which is incremented by one every time the controller reconnects.