sdl2_frt/src/joystick
Sam Lantinga bdc6e4ffc5 Fixed bug 5195 - Replugging in "mixed" controller types crashes on macOS
RustyM

This is related to Bug 5034, but crashes under a somewhat different condition.

In the latest tip (changeset 13914) or with the SDL 2.0.12 source + David?s 5034 patch, unplugging and then replugging in certain controller types on macOS will crash. A mix of new controllers like Switch Pro, PS4 and Xbox One all work without issue. But if a controller without a rumble function, like many SNES retro USB gamepads, is mixed with a PS4 or Switch Pro controller it will crash.

File: joystick/darwin/SDL_sysjoystick.c
Function: static recDevice *FreeDevice(recDevice *removeDevice)
On line 159: while (device->pNext != removeDevice) {
Causes: Thread 1: EXC_BAD_ACCESS (code=1, address=0x188)

This can be reproduced in testgamecontroller" by starting the test program with both a ?retro? controller plugged in and a ?modern rumble? controller (Switch Pro/PS4). This may crash on launch, but it depends on which controller ends up as device 0. If it doesn?t crash, unplug the ?modern rumble? controller and plug it back in.

Some of the "retro" controllers I?ve seen this crash with:
- iBuffalo SNES Controller
- 8Bitdo SN30 Gamepad (in MacOS mode)
- Retrolink NES Controller
- HuiJia SNES Controller Adaptor

The issue appears macOS specific. Seen on 10.12.6 and 10.14.6. Not seen on Windows 10.

The while loop in FreeDevice() assumes that every device is not NULL.

    recDevice *device = gpDeviceList;
    while (device->pNext != removeDevice) {
        device = device->pNext;
    }
    device->pNext = pDeviceNext;

So maybe we should check for NULL here? Or instead prevent adding NULL devices to the list in the first place? Checking device for NULL before entering the loop appears to work.

    recDevice *device = gpDeviceList;
    if (!device) {
        while (device->pNext != removeDevice) {
            device = device->pNext;
        }
    }
    device->pNext = pDeviceNext;
2021-01-14 15:03:11 -08:00
..
android Updated copyright for 2021 2021-01-02 10:25:38 -08:00
bsd Updated copyright for 2021 2021-01-02 10:25:38 -08:00
darwin Fixed bug 5195 - Replugging in "mixed" controller types crashes on macOS 2021-01-14 15:03:11 -08:00
dummy Updated copyright for 2021 2021-01-02 10:25:38 -08:00
emscripten Updated copyright for 2021 2021-01-02 10:25:38 -08:00
haiku Updated copyright for 2021 2021-01-02 10:25:38 -08:00
hidapi Don't blink the Xbox 360 LED when setting the player slot, it's probably already been set by a driver 2021-01-13 11:02:07 -08:00
iphoneos Updated copyright for 2021 2021-01-02 10:25:38 -08:00
linux Updated copyright for 2021 2021-01-02 10:25:38 -08:00
psp Updated copyright for 2021 2021-01-02 10:25:38 -08:00
steam Updated copyright for 2021 2021-01-02 10:25:38 -08:00
virtual Updated copyright for 2021 2021-01-02 10:25:38 -08:00
windows use WIN_StringToUTF8W macro instead of WIN_StringToUTF8, where needed: 2021-01-04 10:00:30 +03:00
check_8bitdo.sh Fixed running on older versions of iOS 2020-04-27 13:31:10 -07:00
controller_type.h Fixed detection of the Wooting Two keyboard, which shows up as an Xbox 360 controller 2021-01-04 17:30:28 -08:00
SDL_gamecontroller.c Updated copyright for 2021 2021-01-02 10:25:38 -08:00
SDL_gamecontrollerdb.h Updated copyright for 2021 2021-01-02 10:25:38 -08:00
SDL_joystick_c.h Updated copyright for 2021 2021-01-02 10:25:38 -08:00
SDL_joystick.c Allow setting the player index to -1, which turns off the player LED for PS5 controllers 2021-01-04 12:24:44 -08:00
SDL_sysjoystick.h Updated copyright for 2021 2021-01-02 10:25:38 -08:00
sort_controllers.py Added support for SDL hints in the game controller mapping database 2020-03-12 19:47:28 -07:00
usb_ids.h Updated copyright for 2021 2021-01-02 10:25:38 -08:00