w3c / gamepad

Gamepad
https://w3c.github.io/gamepad/
Other
142 stars 48 forks source link

GamepadHapticActuator.playEffect() algorithm seems wrong with regards to `[[playingEffectPromise]]` #179

Closed cdumez closed 1 year ago

cdumez commented 1 year ago

GamepadHapticActuator.playEffect() algorithm seems wrong with regards to [[playingEffectPromise]]:

Step 4 says to queue a task to set [[playingEffectPromise]] to undefined. Step 6 says to let [[playingEffectPromise]] be a new promise. I believe The queued in task 4 would thus clear the new promise instead of the one from the previously playing effect.

cdumez commented 1 year ago

cc @marcoscaceres

cdumez commented 1 year ago

We should also watch out for the interaction with the reset() algorithm: https://w3c.github.io/gamepad/extensions.html#dom-gamepadhapticactuator-reset

The reset() algorithm, at step 3, will check synchronously if [[playingEffectPromise]] is undefined. If not undefined, it will queue a task to resolve this.[[playingEffectPromise]] and set it to undefined.

However, since playEffect() may update this.[[playingEffectPromise]] synchronously, it means that the task queued by reset() may clear a [[playingEffectPromise]] that is not the same one that was checked before queueing the task.