Browse Source

Print warnings for invalid XInput device index

Thanks to user m-decoster in PR #217 for the original submission
Mike Lilligreen 11 years ago
parent
commit
688b261970
1 changed files with 13 additions and 1 deletions
  1. 13 1
      engine/source/platformWin32/winDirectInput.cc

+ 13 - 1
engine/source/platformWin32/winDirectInput.cc

@@ -522,11 +522,23 @@ bool DInputManager::isXInputEnabled()
 //------------------------------------------------------------------------------
 //------------------------------------------------------------------------------
 bool DInputManager::isXInputConnected(int controllerID)
 bool DInputManager::isXInputConnected(int controllerID)
 {
 {
+    if (controllerID >= XINPUT_MAX_CONTROLLERS || controllerID < 0)
+    {
+        Con::warnf("Invalid device index: %d. Index should be between 0 and %d.", controllerID, XINPUT_MAX_CONTROLLERS - 1);
+        return false;
+    }
+	
 	return( mXInputStateNew[controllerID].bConnected );
 	return( mXInputStateNew[controllerID].bConnected );
 }
 }
 
 
 int DInputManager::getXInputState(int controllerID, int property, bool current)
 int DInputManager::getXInputState(int controllerID, int property, bool current)
 {
 {
+   if (controllerID >= XINPUT_MAX_CONTROLLERS || controllerID < 0)
+   {
+      Con::warnf("Invalid device index: %d. Index should be between 0 and %d.", controllerID, XINPUT_MAX_CONTROLLERS - 1);
+      return -1;
+   }
+	
    int retVal;
    int retVal;
 
 
    switch(property)
    switch(property)
@@ -848,4 +860,4 @@ void DInputManager::processXInput( void )
       if ( mXInputStateReset ) 
       if ( mXInputStateReset ) 
          mXInputStateReset = false;
          mXInputStateReset = false;
    }
    }
-}
+}