Closed Bug 1606562 Opened 4 years ago Closed 4 years ago

Axes on XInput (Gamepad) on Windows are out of the allowed range

Categories

(Core :: DOM: Device Interfaces, defect, P1)

71 Branch
Desktop
Windows 10
defect

Tracking

()

VERIFIED FIXED
mozilla75
Tracking Status
firefox72 --- wontfix
firefox73 --- wontfix
firefox74 + fixed
firefox75 --- fixed

People

(Reporter: emil.lenngren, Assigned: daoshengmu)

Details

Attachments

(2 files)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36

Steps to reproduce:

Plug in an Xbox One controller on your Windows computer. Then navigate to https://html5gamepad.com/ to try it out and inspect the axis values when tilting the analog sticks maximally.

Actual results:

Minimum left is -1.00003 and maximum down is 1.00003.

Expected results:

According to https://w3c.github.io/gamepad/#dom-gamepad-axes the values must be normalized to the range [-1.0 .. 1.0]. So minimum left should be -1.0 and maximum down should be 1.0.

The bug is here: https://github.com/mozilla/gecko-dev/blob/b222bd7a3952a54fb0b8c965189dfb779caf7f23/dom/gamepad/windows/WindowsGamepad.cpp#L531. The int16_t value is converted to a float by dividing by 32767. But the minimum int16_t value is -32768, and hence the value -1.00003 arises.

This currently breaks games compiled with Emscripten and SDL2. SDL2 gives controller axes as int16_t values. It converts the Gamepad value by multiplying by 32767, followed by a cast to int16_t (http://hg.libsdl.org/SDL/file/0f7577d28c6c/src/joystick/emscripten/SDL_sysjoystick.c#l366). This causes maximum down to become -32768 (which means maximum up), rather than 32767.

Confirmed issue on windows10 64bit using:
Firefox Release 71 affected
Firefox beta 72 affected
Firefox nightly 73.0a1 affected

With chrome this issue is not happening

Steps:
-go to https://html5gamepad.com/
-pressing down the left and right analog stick with xbox one controller
-then pressing left the left and right analog stick with xbox one controller

left analog stick:
left: axis 0 -1.00003
down: axis 1 1.00003

right analog stick:
left: axis 2 -1.00003
down: axis 3 1.00003

Status: UNCONFIRMED → NEW
Component: Untriaged → DOM: Device Interfaces
Ever confirmed: true
OS: Unspecified → Windows 10
Product: Firefox → Core
Hardware: Unspecified → Desktop

It is a bug definitely. I wanna make sure if

left analog stick:
right: axis 0
up: axis 1

right analog stick:
right: axis 2
up: axis 3

work as we expect [-1, 1]? Because SHORT range is [-32768, 32767], it should work correctly when the sThumbXXX is positive.

[1] https://docs.microsoft.com/en-us/windows/win32/api/xinput/ns-xinput-xinput_gamepad

Flags: needinfo?(psanchezm)
Flags: needinfo?(psanchezm) → needinfo?(pablo.muir)
Priority: -- → P1

Yep, up/right work fine, since those come from positive sThumbXXX.

Flags: needinfo?(pablo.muir)
Daosheng Mu

I uploaded a video,
left stick > up, right, down, left
right stick> up, right, down, left

please let me know if you need anything else.
Regards

Assignee: nobody → dmu

sThumbXXX in XInput is a short and its value range is between -32768 and 32767.

Shouldn't const short div = state.Gamepad.sThumbLX > 0 ? 32767 : -32768 be const int div = state.Gamepad.sThumbLX > 0 ? 32767 : 32768 in the patch? Otherwise only the absolute value is used.

div should also be a double by the way otherwise you get integer by integer division which results in 0

(In reply to emil.lenngren from comment #9)

div should also be a double by the way otherwise you get integer by integer division which results in 0

Yes! you're right.

Pushed by dmu@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/504b34d8043d
Fixes XInput thumb value ranges. r=jmathies
Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla75

Since the status are different for nightly and release, what's the status for beta?
For more information, please visit auto_nag documentation.

Is this something we should consider for Beta uplift?

Flags: needinfo?(dmu)

Comment on attachment 9122726 [details]
Bug 1606562 - Fixes XInput thumb value ranges.

Beta/Release Uplift Approval Request

  • User impact if declined: axis values of gamepads will not right (1.0 -> 1.00003)
  • Is this code covered by automated tests?: No
  • Has the fix been verified in Nightly?: Yes
  • Needs manual test from QE?: Yes
  • If yes, steps to reproduce: :Pablo can you help verify it if it works properly? Follow Comment 2 and make sure the values are 1.0 instead of 1.00003.
  • List of other uplifts needed: None
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): This is just a value change to avoid size overflow, so it has no risk.
  • String changes made/needed:
Flags: needinfo?(dmu)
Attachment #9122726 - Flags: approval-mozilla-beta?
Flags: qe-verify+
Flags: needinfo?(pablo.muir)
QA Whiteboard: [qa-triaged]

Comment on attachment 9122726 [details]
Bug 1606562 - Fixes XInput thumb value ranges.

Landed 2 weeks ago with no regression, looks low risk, uplift approved for 74.0b8, thanks.

Attachment #9122726 - Flags: approval-mozilla-beta? → approval-mozilla-beta+

Verified fix on Windows 10 64bit Using Firefox beta 74.0b8 and Nightly 75.0a1

Left stick:
up axis1 = -1.00000
right axis0 = 1.00000
down axis1 = 1.00000
left axis0 = -1.00000

Right stick:
up axis3 = -1.00000
right axis2 = 1.00000
down axis3 = 1.00000
left axis2 = -1.00000

Status: RESOLVED → VERIFIED
Flags: qe-verify+
Flags: needinfo?(pablo.muir)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: