Fixed bug 3561 - Re-acquire device before playing effects if needed.
authorSam Lantinga <slouken@libsdl.org>
Wed, 18 Jan 2017 11:58:16 -0800
changeset 10819bab110e44dcb
parent 10818 7e06b0e4dbe0
child 10820 b0559017b1e5
Fixed bug 3561 - Re-acquire device before playing effects if needed.

Mathieu Laurendeau

Check the result of IDirectInputEffect_SetParameters and re-acquire the device to solve concurrency issues.
src/haptic/windows/SDL_dinputhaptic.c
     1.1 --- a/src/haptic/windows/SDL_dinputhaptic.c	Wed Jan 18 11:57:27 2017 -0800
     1.2 +++ b/src/haptic/windows/SDL_dinputhaptic.c	Wed Jan 18 11:58:16 2017 -0800
     1.3 @@ -1016,6 +1016,19 @@
     1.4      /* Create the actual effect. */
     1.5      ret =
     1.6          IDirectInputEffect_SetParameters(effect->hweffect->ref, &temp, flags);
     1.7 +    if (ret == DIERR_NOTEXCLUSIVEACQUIRED) {
     1.8 +        IDirectInputDevice8_Unacquire(haptic->hwdata->device);
     1.9 +        ret = IDirectInputDevice8_SetCooperativeLevel(haptic->hwdata->device, SDL_HelperWindow, DISCL_EXCLUSIVE | DISCL_BACKGROUND);
    1.10 +        if (SUCCEEDED(ret)) {
    1.11 +            ret = DIERR_NOTACQUIRED;
    1.12 +        }
    1.13 +    }
    1.14 +    if (ret == DIERR_INPUTLOST || ret == DIERR_NOTACQUIRED) {
    1.15 +        ret = IDirectInputDevice8_Acquire(haptic->hwdata->device);
    1.16 +        if (SUCCEEDED(ret)) {
    1.17 +            ret = IDirectInputEffect_SetParameters(effect->hweffect->ref, &temp, flags);
    1.18 +        }
    1.19 +    }
    1.20      if (FAILED(ret)) {
    1.21          DI_SetError("Unable to update effect", ret);
    1.22          goto err_update;