瀏覽代碼

Print warnings for invalid XInput device index

Thanks to user m-decoster in PR #217 for the original submission
Mike Lilligreen 11 年之前
父節點
當前提交
688b261970
共有 1 個文件被更改,包括 13 次插入1 次删除
  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)
 {
+    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 );
 }
 
 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;
 
    switch(property)
@@ -848,4 +860,4 @@ void DInputManager::processXInput( void )
       if ( mXInputStateReset ) 
          mXInputStateReset = false;
    }
-}
+}