From 7033e597b5f540488068fde608fd0eec1e082bbf Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 6 Feb 2014 21:26:41 -0500 Subject: [PATCH] Fixed crash on Windows if haptic isn't initialized when controllers are added. --- src/haptic/windows/SDL_syshaptic.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/haptic/windows/SDL_syshaptic.c b/src/haptic/windows/SDL_syshaptic.c index 6be0e4dcf5857..59f7456683f52 100644 --- a/src/haptic/windows/SDL_syshaptic.c +++ b/src/haptic/windows/SDL_syshaptic.c @@ -221,6 +221,10 @@ DirectInputHaptic_MaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance) DIDEVCAPS capabilities; SDL_hapticlist_item *item = NULL; + if (dinput == NULL) { + return -1; /* not initialized. We'll pick these up on enumeration if we init later. */ + } + /* Make sure we don't already have it */ for (item = SDL_hapticlist; item; item = item->next) { if ( (!item->bXInputHaptic) && (SDL_memcmp(&item->instance, pdidInstance, sizeof (*pdidInstance)) == 0) ) { @@ -286,6 +290,10 @@ DirectInputHaptic_MaybeRemoveDevice(const DIDEVICEINSTANCE * pdidInstance) SDL_hapticlist_item *item; SDL_hapticlist_item *prev = NULL; + if (dinput == NULL) { + return -1; /* not initialized, ignore this. */ + } + for (item = SDL_hapticlist; item != NULL; item = item->next) { if ( (!item->bXInputHaptic) && (SDL_memcmp(&item->instance, pdidInstance, sizeof (*pdidInstance)) == 0) ) { /* found it, remove it. */