Skip to content

fix TypeError in Chrome from GamepadPlugin.stopListeners. It is calli… #7134

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

Conversation

cryonautlex
Copy link

@cryonautlex cryonautlex commented May 7, 2025

…ng the removeAllListeners method on undefined.

This PR

  • Fixes a bug

The gamepad plugin's gamepads array sometimes has undefined values in it, especially in Chrome. Here is a stack trace:

Cannot read properties of undefined (reading 'removeAllListeners')
TypeError: Cannot read properties of undefined (reading 'removeAllListeners')
    at GamepadPlugin.stopListeners (webpack-internal:///./node_modules/phaser/dist/phaser.js:112078:30)
    at GamepadPlugin.shutdown (webpack-internal:///./node_modules/phaser/dist/phaser.js:112275:14)
    at EventEmitter.emit (webpack-internal:///./node_modules/phaser/dist/phaser.js:213:33)
    at InputPlugin.shutdown (webpack-internal:///./node_modules/phaser/dist/phaser.js:107171:27)
    at EventEmitter.emit (webpack-internal:///./node_modules/phaser/dist/phaser.js:215:33)
    at Systems.shutdown (webpack-internal:///./node_modules/phaser/dist/phaser.js:201414:16)
    at SceneManager.stop (webpack-internal:///./node_modules/phaser/dist/phaser.js:198962:23)
    at SceneManager.processQueue (webpack-internal:///./node_modules/phaser/dist/phaser.js:197975:27)
    at SceneManager.update (webpack-internal:///./node_modules/phaser/dist/phaser.js:198219:14)
    at Game.step (webpack-internal:///./node_modules/phaser/dist/phaser.js:17199:20)

This adds a simple if around the call to removeAllListeners to make sure it's not falsy.

@photonstorm
Copy link
Collaborator

I don't mind adding a guard around it, but I wonder what on earth is causing it to have an undefined entry in the first place.

@photonstorm
Copy link
Collaborator

Ok, closing this as resolved via a9164a9 as it needed applying to disconnectAll as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants