Skip to content

Commit

Permalink
DirectInput: use correct joypad id
Browse files Browse the repository at this point in the history
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 godotengine#17566
  • Loading branch information
27thLiz committed Jul 31, 2020
1 parent 7488b07 commit 802a031
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions platform/windows/joypad_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down

0 comments on commit 802a031

Please sign in to comment.