Browse Source

DirectInput: use correct joypad id

Previously `joypad_count` was used as the index into the d_joypads array when initializing a new gamepad.
This caused the accidental override of an already connected device when a gamepad with a lower id was disconnected and connected again.

fixes #17566
Andreas Haas 5 years ago
parent
commit
802a0316c5
1 changed files with 3 additions and 3 deletions
  1. 3 3
      platform/windows/joypad_windows.cpp

+ 3 - 3
platform/windows/joypad_windows.cpp

@@ -146,8 +146,8 @@ bool JoypadWindows::setup_dinput_joypad(const DIDEVICEINSTANCE *instance) {
 	if (have_device(instance->guidInstance) || num == -1)
 		return false;
 
-	d_joypads[joypad_count] = dinput_gamepad();
-	dinput_gamepad *joy = &d_joypads[joypad_count];
+	d_joypads[num] = dinput_gamepad();
+	dinput_gamepad *joy = &d_joypads[num];
 
 	const DWORD devtype = (instance->dwDevType & 0xFF);
 
@@ -171,7 +171,7 @@ bool JoypadWindows::setup_dinput_joypad(const DIDEVICEINSTANCE *instance) {
 	WORD version = 0;
 	sprintf_s(uid, "%04x%04x%04x%04x%04x%04x%04x%04x", type, 0, vendor, 0, product, 0, version, 0);
 
-	id_to_change = joypad_count;
+	id_to_change = num;
 	slider_count = 0;
 
 	joy->di_joy->SetDataFormat(&c_dfDIJoystick2);