SDL
authorAlfred Reynolds <alfred@valvesoftware.com>
Mon, 02 Mar 2015 11:43:24 -0800
changeset 9375bc00287b414f
parent 9374 b577c4753421
child 9376 0495816fec54
SDL
- fix crash on OSX when removing a device. If the remove happened due to the CFRunLoopRunInMode call in SDL_SYS_JoystickDetect then we would delete the device right away, before SDL_SYS_JoystickUpdate could clean it up. So move the CFRunLoopRunInMode to after the cleanup logic, preventing this case. This does mean that adds and removes of joysticks now take 1 extra frame to show up.
src/joystick/darwin/SDL_sysjoystick.c
     1.1 --- a/src/joystick/darwin/SDL_sysjoystick.c	Sun Feb 22 20:34:08 2015 -0500
     1.2 +++ b/src/joystick/darwin/SDL_sysjoystick.c	Mon Mar 02 11:43:24 2015 -0800
     1.3 @@ -560,10 +560,6 @@
     1.4  void
     1.5  SDL_SYS_JoystickDetect()
     1.6  {
     1.7 -    while (CFRunLoopRunInMode(SDL_JOYSTICK_RUNLOOP_MODE,0,TRUE) == kCFRunLoopRunHandledSource) {
     1.8 -        /* no-op. Pending callbacks will fire in CFRunLoopRunInMode(). */
     1.9 -    }
    1.10 -
    1.11      if (s_bDeviceAdded || s_bDeviceRemoved) {
    1.12          recDevice *device = gpDeviceList;
    1.13          s_bDeviceAdded = SDL_FALSE;
    1.14 @@ -613,6 +609,12 @@
    1.15              }
    1.16          }
    1.17      }
    1.18 +
    1.19 +	// run this after the checks above so we don't set device->removed and delete the device before
    1.20 +	// SDL_SYS_JoystickUpdate can run to clean up the SDL_Joystick object that owns this device
    1.21 +	while (CFRunLoopRunInMode(SDL_JOYSTICK_RUNLOOP_MODE,0,TRUE) == kCFRunLoopRunHandledSource) {
    1.22 +		/* no-op. Pending callbacks will fire in CFRunLoopRunInMode(). */
    1.23 +	}
    1.24  }
    1.25  
    1.26  /* Function to get the device-dependent name of a joystick */