Jump to content

Gamepad Disconnection Problems


awbummer
 Share

Recommended Posts

My Phaser.js version: `v2.6.2 "Kore Springs"`

Gamepad: generic Logitech Dual Action controller 

OS: OSX Sierra

Browser: Chrome

Update: I can confirm that this also occurs with an XBOX 360 controller. Also see @Cyclone112's comments below for more troubleshooting info.

I'm adding gamepad support to my current project, and am encountering the following error when disconnecting the gamepad from the USB input:

Uncaught TypeError: Cannot read property 'timestamp' of undefined
    at c.SinglePad.pollStatus (phaser.js:43607)
    at c.Gamepad.update (phaser.js:43003)
    at c.Gamepad.reset (phaser.js:43169)
    at c.Input.reset (phaser.js:37282)
    at c.Game.gameResumed (phaser.js:36532)
    at c.Stage.visibilityChange (phaser.js:31966)
    at HTMLDocument._onChange (phaser.js:31905)

This happens regardless of whether or not I register `onDisconnectCallback` to the gamepad. May also be worth mentioning that I encounter the error when disconnecting from this example: https://phaser.io/examples/v2/input/gamepad-buttons

If the Github issue tracker would be a more appropriate place for this, I can post there instead. Any recommendations for a workaround would be great. Thanks!

Link to comment
Share on other sites

HTML5 gamepad support is still in an experimental stage and I'm just talking about in general, not Phaser itself. I just added Gamepad support to my game yesterday and I never had that issue.

Perhaps it's the gamepad you used? I tested with an XBOX ONE and PS4 controller and both worked fine connecting/disconnecting.

Also might depend on the browser you were testing with

Link to comment
Share on other sites

So I confirmed that I get the same error you do on the example page but I know I don't in my game. So that's a good thing. I'll compare my code to the example and try to see why that would happen. It's Valentine's Day today though so I'll have to properly look into this issue tomorrow night as my girlfriend will murder me otherwise :).

Link to comment
Share on other sites

Well I spent some time investigating and I'm just frustrated to no end right now. Perhaps someone else has setup multiple gamepad support in there game and could help both of us out.

It might not be something that can be solved within Phaser either as I tested on 2 different PC's to different results just using this site here: http://html5gamepad.com/

PC #1

  • When I hook up 2 controllers they both show and work fine.
  • If I unplug controller 2 then controller 1 still works fine.
  • If I replug in controller 2 they both work fine.
  • If I unplug controller 1 it disconnects BOTH controllers

PC #2

  • When I hook up 1 controller it works fine
  • When I connect the second controller I get a third random invalid controller showing which you can see a screenshot of here
  • When I unplug either controller the third random one disappears

I do see the exception you got but it seems to only occur in certain scenarios for me. I was able to avoid the game crashing by just adding an extra check in the pollStatus function in SinglePad like so:

if (!this.connected || !this.game.input.enabled || !this.game.input.gamepad.enabled || !this._rawPad || (this._rawPad.timestamp && (this._rawPad.timestamp === this._prevTimestamp)))

The disconnect callback is still called properly and I can reconnect the controller and keep playing just fine. This seems to avoid any crashes or ill effects and might just be what you need if your game only supports a single player.

If your game is meant for up to 4 people locally then you will still probably have some issues like I'm experiencing in the PC #1 and #2 descriptions above

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...