From 1005c93402bb42019b2657af7d80a8a61a5c7047 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 2 Mar 2014 00:02:56 -0500 Subject: [PATCH] Windows: Fixed crash if quitting without closing an XInput haptic device. --- src/haptic/windows/SDL_syshaptic.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/haptic/windows/SDL_syshaptic.c b/src/haptic/windows/SDL_syshaptic.c index 8454d93965672..a4b5e42644a48 100644 --- a/src/haptic/windows/SDL_syshaptic.c +++ b/src/haptic/windows/SDL_syshaptic.c @@ -939,20 +939,32 @@ SDL_SYS_HapticQuit(void) { SDL_hapticlist_item *item; SDL_hapticlist_item *next = NULL; - - if (loaded_xinput) { - WIN_UnloadXInputDLL(); - loaded_xinput = SDL_FALSE; + SDL_Haptic *hapticitem = NULL; + + extern SDL_Haptic *SDL_haptics; + for (hapticitem = SDL_haptics; hapticitem; hapticitem = hapticitem->next) { + if ((hapticitem->hwdata->bXInputHaptic) && (hapticitem->hwdata->thread)) { + /* we _have_ to stop the thread before we free the XInput DLL! */ + hapticitem->hwdata->stopThread = 1; + SDL_WaitThread(hapticitem->hwdata->thread, NULL); + hapticitem->hwdata->thread = NULL; + } } for (item = SDL_hapticlist; item; item = next) { /* Opened and not closed haptics are leaked, this is on purpose. * Close your haptic devices after usage. */ + /* !!! FIXME: (...is leaking on purpose a good idea?) */ next = item->next; SDL_free(item->name); SDL_free(item); } + if (loaded_xinput) { + WIN_UnloadXInputDLL(); + loaded_xinput = SDL_FALSE; + } + if (dinput != NULL) { IDirectInput8_Release(dinput); dinput = NULL;