src/haptic/windows/SDL_syshaptic.c
changeset 5591 17beb16fa838
parent 5539 b305e3c2d2e7
child 6138 4c64952a58fb
     1.1 --- a/src/haptic/windows/SDL_syshaptic.c	Thu Aug 04 01:07:13 2011 -0400
     1.2 +++ b/src/haptic/windows/SDL_syshaptic.c	Wed Aug 03 04:22:47 2011 -0400
     1.3 @@ -68,6 +68,7 @@
     1.4  /*
     1.5   * Internal stuff.
     1.6   */
     1.7 +static SDL_bool coinitialized = SDL_FALSE;
     1.8  static LPDIRECTINPUT dinput = NULL;
     1.9  
    1.10  
    1.11 @@ -147,15 +148,18 @@
    1.12  
    1.13      SDL_numhaptics = 0;
    1.14  
    1.15 -    ret = CoInitialize(NULL);
    1.16 +    ret = WIN_CoInitialize();
    1.17      if (FAILED(ret)) {
    1.18          DI_SetError("Coinitialize", ret);
    1.19          return -1;
    1.20      }
    1.21  
    1.22 +    coinitialized = SDL_TRUE;
    1.23 +
    1.24      ret = CoCreateInstance(&CLSID_DirectInput, NULL, CLSCTX_INPROC_SERVER,
    1.25                             &IID_IDirectInput, (LPVOID) & dinput);
    1.26      if (FAILED(ret)) {
    1.27 +        SDL_SYS_HapticQuit();
    1.28          DI_SetError("CoCreateInstance", ret);
    1.29          return -1;
    1.30      }
    1.31 @@ -163,12 +167,14 @@
    1.32      /* Because we used CoCreateInstance, we need to Initialize it, first. */
    1.33      instance = GetModuleHandle(NULL);
    1.34      if (instance == NULL) {
    1.35 +        SDL_SYS_HapticQuit();
    1.36          SDL_SetError("GetModuleHandle() failed with error code %d.",
    1.37                       GetLastError());
    1.38          return -1;
    1.39      }
    1.40      ret = IDirectInput_Initialize(dinput, instance, DIRECTINPUT_VERSION);
    1.41      if (FAILED(ret)) {
    1.42 +        SDL_SYS_HapticQuit();
    1.43          DI_SetError("Initializing DirectInput device", ret);
    1.44          return -1;
    1.45      }
    1.46 @@ -181,6 +187,7 @@
    1.47                                     DIEDFL_FORCEFEEDBACK |
    1.48                                     DIEDFL_ATTACHEDONLY);
    1.49      if (FAILED(ret)) {
    1.50 +        SDL_SYS_HapticQuit();
    1.51          DI_SetError("Enumerating DirectInput devices", ret);
    1.52          return -1;
    1.53      }
    1.54 @@ -664,8 +671,15 @@
    1.55          }
    1.56      }
    1.57  
    1.58 -    IDirectInput_Release(dinput);
    1.59 -    dinput = NULL;
    1.60 +    if (dinput != NULL) {
    1.61 +        IDirectInput_Release(dinput);
    1.62 +        dinput = NULL;
    1.63 +    }
    1.64 +
    1.65 +    if (coinitialized) {
    1.66 +        WIN_CoUninitialize();
    1.67 +        coinitialized = SDL_FALSE;
    1.68 +    }
    1.69  }
    1.70  
    1.71