Skip to content

Commit

Permalink
Windows: Fixed crash if quitting without closing an XInput haptic dev…
Browse files Browse the repository at this point in the history
…ice.
  • Loading branch information
icculus committed Mar 2, 2014
1 parent 754067d commit 1005c93
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/haptic/windows/SDL_syshaptic.c
Expand Up @@ -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;
Expand Down

0 comments on commit 1005c93

Please sign in to comment.