# HG changeset patch # User David Ludwig # Date 1584401065 14400 # Mon Mar 16 19:24:25 2020 -0400 # Node ID af5d105f9babbb65b14d77e238308d200422a6ce # Parent 355a4f94a782747a990b2fedaebc7bebd280e153 Fixed Bug 5034 - Replugging in a controller crashes on macOS in SDL 2.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. diff -r 355a4f94a782 -r af5d105f9bab src/joystick/darwin/SDL_sysjoystick.c --- a/src/joystick/darwin/SDL_sysjoystick.c Tue Mar 10 18:35:31 2020 -0700 +++ b/src/joystick/darwin/SDL_sysjoystick.c Mon Mar 16 19:24:25 2020 -0400 @@ -125,6 +125,7 @@ FreeDevice(recDevice *removeDevice) { recDevice *pDeviceNext = NULL; + SDL_Joystick *joystick = NULL; if (removeDevice) { if (removeDevice->deviceRef) { IOHIDDeviceUnscheduleFromRunLoop(removeDevice->deviceRef, CFRunLoopGetCurrent(), SDL_JOYSTICK_RUNLOOP_MODE); @@ -146,6 +147,14 @@ } 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); @@ -891,6 +900,10 @@ /* 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(); }