Windows: Fixed crash if quitting without closing an XInput haptic device.
authorRyan C. Gordon
Sun, 02 Mar 2014 00:02:56 -0500
changeset 8281f280c6b5d08c
parent 8280 860092ac58d6
child 8282 484d2404c472
Windows: Fixed crash if quitting without closing an XInput haptic device.
src/haptic/windows/SDL_syshaptic.c
     1.1 --- a/src/haptic/windows/SDL_syshaptic.c	Sat Mar 01 22:27:21 2014 -0500
     1.2 +++ b/src/haptic/windows/SDL_syshaptic.c	Sun Mar 02 00:02:56 2014 -0500
     1.3 @@ -939,20 +939,32 @@
     1.4  {
     1.5      SDL_hapticlist_item *item;
     1.6      SDL_hapticlist_item *next = NULL;
     1.7 +    SDL_Haptic *hapticitem = NULL;
     1.8  
     1.9 -    if (loaded_xinput) {
    1.10 -        WIN_UnloadXInputDLL();
    1.11 -        loaded_xinput = SDL_FALSE;
    1.12 +    extern SDL_Haptic *SDL_haptics;
    1.13 +    for (hapticitem = SDL_haptics; hapticitem; hapticitem = hapticitem->next) {
    1.14 +        if ((hapticitem->hwdata->bXInputHaptic) && (hapticitem->hwdata->thread)) {
    1.15 +            /* we _have_ to stop the thread before we free the XInput DLL! */
    1.16 +            hapticitem->hwdata->stopThread = 1;
    1.17 +            SDL_WaitThread(hapticitem->hwdata->thread, NULL);
    1.18 +            hapticitem->hwdata->thread = NULL;
    1.19 +        }
    1.20      }
    1.21  
    1.22      for (item = SDL_hapticlist; item; item = next) {
    1.23          /* Opened and not closed haptics are leaked, this is on purpose.
    1.24           * Close your haptic devices after usage. */
    1.25 +        /* !!! FIXME: (...is leaking on purpose a good idea?) */
    1.26          next = item->next;
    1.27          SDL_free(item->name);
    1.28          SDL_free(item);
    1.29      }
    1.30  
    1.31 +    if (loaded_xinput) {
    1.32 +        WIN_UnloadXInputDLL();
    1.33 +        loaded_xinput = SDL_FALSE;
    1.34 +    }
    1.35 +
    1.36      if (dinput != NULL) {
    1.37          IDirectInput8_Release(dinput);
    1.38          dinput = NULL;