Skip to content

Commit

Permalink
Fixed Bug 5034 - Replugging in a controller crashes on macOS in SDL 2…
Browse files Browse the repository at this point in the history
….0.12

The Darwin/macOS joystick driver was freeing its joystick's hwdata field
without zeroing it out in any live instance of SDL_Joystick.
  • Loading branch information
DavidLudwig committed Mar 16, 2020
1 parent 47da53b commit 197b14d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/joystick/darwin/SDL_sysjoystick.c
Expand Up @@ -125,6 +125,7 @@ static recDevice *
FreeDevice(recDevice *removeDevice)
{
recDevice *pDeviceNext = NULL;
SDL_Joystick *joystick = NULL;
if (removeDevice) {
if (removeDevice->deviceRef) {
IOHIDDeviceUnscheduleFromRunLoop(removeDevice->deviceRef, CFRunLoopGetCurrent(), SDL_JOYSTICK_RUNLOOP_MODE);
Expand All @@ -146,6 +147,14 @@ FreeDevice(recDevice *removeDevice)
}
removeDevice->pNext = NULL;

/* clear out any reference to this recDevice that are being
* held by a live instance of SDL_Joystick
*/
joystick = SDL_JoystickFromInstanceID(removeDevice->instance_id);
if (joystick) {
joystick->hwdata = NULL;
}

/* free element lists */
FreeElementList(removeDevice->firstAxis);
FreeElementList(removeDevice->firstButton);
Expand Down Expand Up @@ -871,6 +880,10 @@ DARWIN_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint
/* Scale and average the two rumble strengths */
Sint16 magnitude = (Sint16)(((low_frequency_rumble / 2) + (high_frequency_rumble / 2)) / 2);

if (!device) {
return SDL_SetError("Rumble failed, device disconnected");
}

if (!device->ffservice) {
return SDL_Unsupported();
}
Expand Down

0 comments on commit 197b14d

Please sign in to comment.