Closed Bug 893785 Opened 6 years ago Closed 6 years ago
Gamepad API - Combat demo shows wrong number of elements
Reproducible on latest Aurora 24.0a2 (BuildID: 20130715004002): Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20130715 Firefox/24.0; Reproducible on latest Nightly 25.0a1 (BuildID: 20130715030202): Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20130715 Firefox/25.0 STR: 1. Plug in a controller. 2. Launch Firefox. 3. Navigate to http://people.mozilla.com/~tmielczarek/combat/. 4. Open a new window (Ctrl+N) or a private browsing window (Ctrl+Shift+P) and repeat step 3. 5. Repeat step 4 a couple of times. Expected results: The number of tanks is the same in all windows. Actual results: The number of tanks is increased. Notes: 1. Tested with a Xbox 360 controller. 2. If I open a new tab and repeat step 3, this issue is not reproducible; if the tab is dragged out and refreshed, this issue is reproduced.
There's clearly some bug here with firing gamepadconnected events. I can reproduce this on Linux as well. The reason this doesn't work if you use a new tab instead of a new window is because we don't send events to non-visible pages, so background tabs don't get them. I can also reproduce this using the simpler testcase: http://people.mozilla.com/~tmielczarek/gamepadtest.html Open that in a window and leave it visible, then open a new window with that same page and press a button on the gamepad. If you repeatedly reload the second page and press a gamepad button, the first page will receive a gamepadconnected event every time.
Apparently it's just the events being sent erroneously, because navigator.getGamepads().length == 1 on the first page, no matter how many of the bogus events it gets.
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:25.0) Gecko/20130716 Firefox/25.0 Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:25.0) Gecko/20130716 Firefox/24.0 Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20130721 Firefox/24.0 Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20130721 Firefox/25.0 Also reproducible on Ubuntu and Mac OS X; changing the platform to all.
OS: Windows 7 → All
Hardware: x86_64 → All
Sorry for my typo from above. The correct User Agents are: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20130722 Firefox/24.0 Mozilla/5.0 (X11; Linux i686; rv:25.0) Gecko/20130718 Firefox/25.0 Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20130720 Firefox/24.0 Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:25.0) Gecko/20130720 Firefox/25.0
Can QA help identify if this is a Fx24 regression ? Or is the same bug hit in previous firefox versions?
The Gamepad API did not ship in Firefox prior to Firefox 24, so this is not a regression, it's a bug in a new feature. Additionally, the API will be preffed off in release, so it's not the end of the world. I haven't had time to look at this yet (was on vacation), but it's not likely to be a huge bug, so it's possible I can get a fix landed and backport it to Aurora soon.
(In reply to Ted Mielczarek [:ted.mielczarek] (post-vacation backlog) from comment #6) > The Gamepad API did not ship in Firefox prior to Firefox 24, so this is not > a regression, it's a bug in a new feature. > > Additionally, the API will be preffed off in release, so it's not the end of > the world. I haven't had time to look at this yet (was on vacation), but > it's not likely to be a huge bug, so it's possible I can get a fix landed > and backport it to Aurora soon. Thanks TEed ! Not tracking given your comment but a low risk uplift will be considered based on where we are in the cycle.
Okay, so this is a stupid bug caused by me using NewConnectionEvent when button/axis move events are fired. That function sends connection events to *all* listeners, which is clearly not what we want. Instead I changed them to just use FireConnectionEvent, which sends a single connection event. There are a few unrelated cleanups in NewConnectionEvent, I thought I needed to fix something there so I cleaned that up slightly while I was there, but I didn't actually need to. I wrote the test first, verified that it failed without this patch, and passed with the patch.
Attachment #783916 - Flags: review?(bugs)
I also verified that the issue reported in comment 0 doesn't appear with this patch.
smaug asked for clarification on IRC, so here's some more info: The New*Event methods send an event to all windows that are listening for gamepad events and are also in a visible state. The Fire*Event methods send an event to a specific window. This code was previously using NewConnectionEvent when it wanted to send a gamepadconnected event to a window that hadn't previously seen the gamepad in question. This is just wrong, it should have been using FireConnectionEvent to send an event to just that specific window. If you think the method names are confusing in retrospect, I'm open to renaming them (although the New*Event methods are public API, but not called from so many places that it'd be hard to change them).
Comment on attachment 783916 [details] [diff] [review] don't fire gamepadconnected events for windows that have already received them Could you add that comment to .h where those methods are declared.
Attachment #783916 - Flags: review?(bugs) → review+
Comment on attachment 783916 [details] [diff] [review] don't fire gamepadconnected events for windows that have already received them [Approval Request Comment] Bug caused by (feature/regressing bug #): bug 604039, this is a bug in the initial implementation of this new feature (Gamepad API). User impact if declined: Extraneous gamepadconnected events will be fired to web cotnent. Testing completed (on m-c, etc.): Patch includes an automated test, manual testing completed with self builds. Risk to taking this patch (and alternatives if risky): Gamepad API is preffed off by default, so this should have very little impact, but it would be nice to not ship this feature (even if preffed off) with this silly bug. String or IDL/UUID changes made by this patch: None
Attachment #783916 - Flags: approval-mozilla-aurora?
Attachment #783916 - Flags: approval-mozilla-aurora? → approval-mozilla-aurora+
You need to log in before you can comment on or make changes to this bug.