Windows: Fixed crash if quitting without closing an XInput haptic device.
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;