Skip to content
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

Crash while disconnecting a controller #552

Closed
cmitu opened this issue Mar 28, 2019 · 7 comments
Closed

Crash while disconnecting a controller #552

cmitu opened this issue Mar 28, 2019 · 7 comments

Comments

@cmitu
Copy link

cmitu commented Mar 28, 2019

I'm experiencing a possibly related issue to the SDL update to 2.0.9, on a pretty much stock 4.4.11, Pi 3B.

If I unplug the 2nd controller while ES is running, it crashes and I get the dialog with 'ES Crashed...' https://github.com/RetroPie/RetroPie-Setup/blob/1446ce55fa269fc757a9deb649105405865513db/scriptmodules/supplementary/emulationstation.sh#L231).

I used 2 USB controllers - a regular SNES clone (the Buffalo) and a DS4. When unplugging the DS4, I got the crash dialog. I reproduced the crash again with another 2SNES-to-USB controller, by unplugging it.
It might have something to do with the fact that both controllers add multiple input devices, because it doesn't seem to crash when disconnecting the iBuffalo controller.

Here's a debug output before the crash

vl3: 	SystemView::getViewElements()
lvl2: 	Added unconfigured joystick raphnet technologies Dual SNES to USB v2.2 (GUID: 030000009b2800005700000001010000, instance ID: 1, device index: 1).
lvl2: 	Added unconfigured joystick raphnet technologies Dual SNES to USB v2.2 (GUID: 030000009b2800005700000001010000, instance ID: 2, device index: 2).
lvl3: 	UIModeController::logInput( raphnet technologies Dual SNES to USB v2.2 ):Axis 0-, isMappedTo= , value=0
lvl3: 	UIModeController::logInput( raphnet technologies Dual SNES to USB v2.2 ):Axis 0-, isMappedTo= , value=-1
lvl3: 	UIModeController::logInput( raphnet technologies Dual SNES to USB v2.2 ):Axis 1-, isMappedTo= , value=0
lvl3: 	UIModeController::logInput( raphnet technologies Dual SNES to USB v2.2 ):Axis 1-, isMappedTo= , value=-1
lvl3: 	UIModeController::logInput( raphnet technologies Dual SNES to USB v2.2 ):Axis 0-, isMappedTo= , value=0
lvl3: 	UIModeController::logInput( raphnet technologies Dual SNES to USB v2.2 ):Axis 0-, isMappedTo= , value=-1
lvl3: 	UIModeController::logInput( raphnet technologies Dual SNES to USB v2.2 ):Axis 1-, isMappedTo= , value=0
lvl3: 	UIModeController::logInput( raphnet technologies Dual SNES to USB v2.2 ):Axis 1-, isMappedTo= , value=-1

Thread 1 "emulationstatio" received signal SIGSEGV, Segmentation fault.
0x00155960 in InputManager::parseEvent(SDL_Event const&, Window*) ()
(gdb) bt
#0  0x00155960 in InputManager::parseEvent(SDL_Event const&, Window*) ()
#1  0x000618b0 in main ()

EDIT: seem definitely related to the controller type - if I unplug the iBuffalo, the crash doesn't occur - it's only when I unplug the DS4 or the 2SNES-to-USB adapter.

EDIT 2: I downgraded to 2.0.8 and I can't reproduce the crash using the same test.

@cmitu cmitu changed the title Crash while disconnecting a (2nd) controller Crash while disconnecting a controller Mar 28, 2019
@cmitu
Copy link
Author

cmitu commented Mar 30, 2019

So far it seems a libsdl issue, related to generating events after disconnecting the controller.
Using a SDL2 built with SDL_DEBUG_EVENTS and the SDL provided testhotplug.c program, this is the difference when plugging and un-plugging the gamepad:

== Using 2.0.9

SDL EVENT: SDL_JOYDEVICEADDED (timestamp=91775 which=0)
SDL EVENT: SDL_JOYDEVICEADDED (timestamp=92175 which=1)
SDL EVENT: SDL_JOYAXISMOTION (timestamp=92395 which=3 axis=0 value=0)
SDL EVENT: SDL_JOYAXISMOTION (timestamp=92395 which=3 axis=0 value=-32768)
SDL EVENT: SDL_JOYAXISMOTION (timestamp=92395 which=3 axis=1 value=0)
SDL EVENT: SDL_JOYAXISMOTION (timestamp=92395 which=3 axis=1 value=-32768)
INFO: Joy Added  : 0 : raphnet technologies Dual SNES to USB v2.2
INFO: No haptic found
INFO: Only one joystick supported by this test
SDL EVENT: SDL_JOYDEVICEREMOVED (timestamp=107490 which=4)
INFO: Unknown joystick diconnected
SDL EVENT: SDL_JOYDEVICEREMOVED (timestamp=107640 which=3)
SDL EVENT: SDL_JOYAXISMOTION (timestamp=107640 which=3 axis=0 value=0)
SDL EVENT: SDL_JOYAXISMOTION (timestamp=107640 which=3 axis=1 value=0)
INFO: Joy Removed: 3

== Using 2.0.8

SDL EVENT: SDL_JOYDEVICEADDED (timestamp=22955 which=1)
SDL EVENT: SDL_JOYDEVICEADDED (timestamp=23354 which=2)
INFO: Only one joystick supported by this test
INFO: Only one joystick supported by this test
SDL EVENT: SDL_JOYDEVICEREMOVED (timestamp=32188 which=2)
INFO: Unknown joystick diconnected
SDL EVENT: SDL_JOYDEVICEREMOVED (timestamp=32329 which=1)
INFO: Unknown joystick diconnected

It looks like some spurious SDL_JOYAXISMOTION events are generated on connect/disconnect on 2.0.9 and ES crashes trying to interpret a SDL_JOYAXISMOTION event for a device that's no longer available. So the problem is not related to disconnecting a device that has multiple inputs associated, but rather disconnecting a device that reports a Joystick present.

Testing with just one DS4 controller, the crash is easily reproduced - just connect it and then disconnect it while ES is running. Moreover, using a DS4, I can see the event queue is continuously spammed with SDL_JOYAXISMOTION without even touching the controller:

[...]
SDL EVENT: SDL_JOYAXISMOTION (timestamp=24706 which=0 axis=1 value=8482)
SDL EVENT: SDL_JOYAXISMOTION (timestamp=24706 which=0 axis=2 value=-3850)
SDL EVENT: SDL_JOYAXISMOTION (timestamp=24722 which=0 axis=3 value=363)
SDL EVENT: SDL_JOYAXISMOTION (timestamp=24722 which=0 axis=4 value=-177)
SDL EVENT: SDL_JOYAXISMOTION (timestamp=24722 which=0 axis=5 value=77)
SDL EVENT: SDL_JOYAXISMOTION (timestamp=24722 which=0 axis=0 value=4237)
SDL EVENT: SDL_JOYAXISMOTION (timestamp=24722 which=0 axis=1 value=8445)
SDL EVENT: SDL_JOYAXISMOTION (timestamp=24722 which=0 axis=2 value=-4074)
SDL EVENT: SDL_JOYAXISMOTION (timestamp=24722 which=0 axis=3 value=298)
SDL EVENT: SDL_JOYAXISMOTION (timestamp=24722 which=0 axis=4 value=-296)
SDL EVENT: SDL_JOYAXISMOTION (timestamp=24722 which=0 axis=5 value=24)
SDL EVENT: SDL_JOYAXISMOTION (timestamp=24722 which=0 axis=0 value=4297)
SDL EVENT: SDL_JOYAXISMOTION (timestamp=24722 which=0 axis=1 value=8525)
SDL EVENT: SDL_JOYAXISMOTION (timestamp=24722 which=0 axis=2 value=-3911)
SDL EVENT: SDL_JOYAXISMOTION (timestamp=24722 which=0 axis=3 value=238)
SDL EVENT: SDL_JOYAXISMOTION (timestamp=24722 which=0 axis=4 value=-406)
[.. and so on ..]

NOTE: It seems to only happen on Raspbian, I tested this also on Ubuntu 18.04, but could not reproduce the crash.

@cmitu
Copy link
Author

cmitu commented Apr 3, 2019

So it looks like something similar got reported in https://retropie.org.uk/forum/topic/21846/. I was afraid it was a local thing, particular to my system. I did some more testing after my last update and noticed the DS4 issue was not appearing 100%, but connecting and disconnecting it would eventually make the spurious events appear.

I tested also with the lastest SDL (from their Hg repo) and I don't see the problem manifesting - though this doesn't have the RP patches applied.

I also found a workaround for this particular issue (the crash), by discarding any SDL_JOYAXISMOTION events (via SDL_FlushEvent) after a disconnect event, but this wouldn't solve the constant spamming of the Event queue that I've seen with the DS4 tests.

@joolswills do you want me to submit a PR with the workaround until we sort things out ?

@nadenislamarre
Copy link

issue created on sdl bug tracker : https://bugzilla.libsdl.org/show_bug.cgi?id=4640

@cmitu
Copy link
Author

cmitu commented May 22, 2019

@nadenislamarre Can you reproduce the problem using the SDL2 latest version (hg.libsdl.org) ? At the time I tested this, the problem seems to have been resolved sometime between the 2.0.9 release tag and current master.

@shantigilbert
Copy link

@cmitu I still have the problem with the current master, specially with a DS4 gamepad, if you disconnect it or shake it a little bit ES will crash as well with other game pads, if you connect and disconnect them.

@cmitu
Copy link
Author

cmitu commented Jun 30, 2019

OK, re-tested again and the spurious events are generated also on latest SDL (with 2.0.10 close to release). I wasn't testing by removing the controller while still pressing the joysticks (i.e. joysticks released).
I tested the patch from @nadenislamarre, it seems to work by removing the extra motion events - presumably from the SDL sending the re-center events after disconnect.

@cmitu
Copy link
Author

cmitu commented Sep 8, 2019

I'm closing this issue - it's fixed applying the patch provided by @nadenislamarre and it's not an Emulationstation bug per-se.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants