-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GamePads.update() doesn't remove entries from current
upon gamepad disconnect
#1014
Comments
I recently pushed this code in a PR as a fix for something, and I guess I broke something else! I wonder if just a simple fix where you loop over |
I think the bug existed prior to your recent submission as well - so I don't think your recent PR regressed this :) Your suggestion sounds like it should do the trick though! |
I've been thinking about this, and I just realized that might not be good enough @ransico . If you connected gamepads A and B, then current would look like this:
So
Where What doesn't change is I guess the question is, should PlayCanvas be handling making the the gamepads persistent in the array (we could index it by |
Sorry for the delayed response - I've been out of the office for the past 10 days! No easy answers on this one - the gamepads API doesn't really support the notion of 'pinning' a physical controller to a particular player number (especially across disconnect/reconnect). If the number and ordering of gamepads mattered strongly to a developer across disconnect/reconnect, I suspect they would need to detect a change in the number of connected gamepads and respond by pausing the app, presenting a dialog of some description allowing players to 'reclaim' their controlled avatar. I don't have a strong opinion on whether you should introduce gaps in the array; while it does introduce consistency with the Gamepad API - that is always subject to change since it is not a ratified standard no may be an own-goal in the long run. Additionally, introducing gaps could be more error prone in apps, since developers will need to check for nulls (and not just take gamepad 0) |
When a gamepad is disconnected, it should also be removed from the
app.gamepads.current
andapp.gamepads.previous
arrays.It seems that the logic in the
update
method only iterates over the number of devices returned fromPoll()
, so doesn't get a chance to set excess entries to null:engine/src/input/game-pads.js
Line 109 in d4b8e0a
The text was updated successfully, but these errors were encountered: