Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/platform/input/game-pads.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,13 +534,20 @@ class GamePad {
const previousAxes = this._previousAxes;
const axes = this._axes;

// resizing array if size changed
axes.length = gamepad.axes.length;
previousAxes.length = gamepad.axes.length;


// Store previous values for axes for dual buttons.
previousAxes.length = 0;
previousAxes.push(...axes);
for(let i = 0; i<axes.length; i++) {
previousAxes[i] = axes[i];
}

// Update axes
axes.length = 0;
axes.push(...gamepad.axes);
for(let i = 0; i<gamepad.axes.length; i++) {
axes[i] = gamepad.axes[i];
}

// Update buttons
const buttons = this._buttons;
Expand Down Expand Up @@ -877,7 +884,7 @@ class GamePads extends EventHandler {
}

for (let j = 0, m = buttons.length; j < m; j++) {
const button = buttons[i];
const button = buttons[j];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you mean to change i -> j?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes — this change was intentional.
The inner loop iterates using j, but the original code accessed buttons[i].
That caused incorrect indexing since i belongs to the outer loop.

This was a small existing bug that I fixed while making the main change (in-place axes updates).
If you'd prefer, I can move this fix into a separate PR

this.previous[i][j] = button ? !button.wasPressed && button.pressed || button.wasReleased : false;
}
}
Expand Down