From abdcb7d299d13969c03b9c812a069454054a2a37 Mon Sep 17 00:00:00 2001 From: Andreas Haas <27thLiz@gmail.com> Date: Fri, 31 Jul 2020 20:16:51 +0200 Subject: [PATCH] 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 (cherry picked from commit 802a0316c56c954d10c0d7f0c7bb44f3298d2c8f) --- platform/windows/joypad_windows.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platform/windows/joypad_windows.cpp b/platform/windows/joypad_windows.cpp index 1abd2d162dd..74b1d72e49c 100644 --- a/platform/windows/joypad_windows.cpp +++ b/platform/windows/joypad_windows.cpp @@ -153,8 +153,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); @@ -178,7 +178,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);