Skip to content

Commit 504b4f1

Browse files
authored
Merge pull request #90 from ProjectLighthouseCAU/fix-duplicate-gamepad-events
Fix duplicate gamepad events
2 parents 96e64cb + e8668c7 commit 504b4f1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/screens/home/displays/DisplayView.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ export function DisplayView() {
168168
const changes = diffGamepadStates(lastStates, states);
169169

170170
if (changes.length > 0) {
171+
// NOTE: It is important that we assign lastStates before any await
172+
// points to avoid having later iterations of the polling loop
173+
// interleave and potentially firing duplicate events, see
174+
// https://github.com/ProjectLighthouseCAU/luna/issues/89
175+
lastStates = states;
176+
171177
if (inputConfig.legacyMode) {
172178
// Convert and send events to the legacy API
173179
const legacyEvents: LegacyControllerEvent[] = changes
@@ -209,8 +215,6 @@ export function DisplayView() {
209215
}));
210216
}
211217
}
212-
213-
lastStates = states;
214218
}
215219
}, 10);
216220
console.log('Registered gamepad polling loop', interval);

0 commit comments

Comments
 (0)