Fix case where 2 gamepads are disconnected at once

This commit is contained in:
Ethan O'Brien 2025-05-12 00:01:23 -05:00
parent 908bccd63c
commit a1efedfbea
No known key found for this signature in database
GPG Key ID: 7A6E7CCD3BD93AB1

View File

@ -1121,7 +1121,8 @@ class EmulatorJS {
this.updateGamepadLabels();
})
this.gamepad.on('disconnected', (e) => {
const gamepadSelection = this.gamepad.gamepads[e.gamepadIndex].id + "_" + this.gamepad.gamepads[e.gamepadIndex].index;
const gamepadIndex = this.gamepad.gamepads.indexOf(this.gamepad.gamepads.find(f => f.index == e.gamepadIndex));
const gamepadSelection = this.gamepad.gamepads[gamepadIndex].id + "_" + this.gamepad.gamepads[gamepadIndex].index;
for (let i = 0; i < this.gamepadSelection.length; i++) {
if (this.gamepadSelection[i] === gamepadSelection) {
this.gamepadSelection[i] = "";