Skip to content
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

Error when destroying game object in touch input event handler #4463

Closed
SachsKaylee opened this issue Apr 7, 2019 · 2 comments
Closed

Error when destroying game object in touch input event handler #4463

SachsKaylee opened this issue Apr 7, 2019 · 2 comments

Comments

@SachsKaylee
Copy link

Version

  • Phaser Version: Phaser v3.16.2 (WebGL | Web Audio)
  • Operating system: Ubuntu 18.04.2 LTS
  • Browser: Google Chrome 73.0.3683.103 (Official Build) (64-bit)

OS and Browser should not be relevant to this issue.

Description

If a game object gets destroyed in a touch event(In my case a GAMEOBJECT_POINTER_UP caused by touching) the InputPlugin throws the following error:

InputPlugin.js:1497 Uncaught TypeError: Cannot read property 'localX' of undefined
    at InputPlugin.processUpEvents (InputPlugin.js:1497)
    at InputPlugin.update (InputPlugin.js:620)
    at InputManager.updateInputPlugins (InputManager.js:990)
    at InputManager.queueTouchEnd (InputManager.js:1111)
    at HTMLCanvasElement.onTouchEnd (TouchManager.js:226)

This is due to the plugin emitting the GAMEOBJECT_POINTER_UP and then immediately trying to emit the GAMEOBJECT_POINTER_OUT event a few lines later without checking if the game object still exists.

https://github.com/photonstorm/phaser/blob/0db663d901b89f4ffdfff53458dbaf2818ff8dab/src/input/InputPlugin.js#L1490-L1498

Example Test Code

const testImg = this.add.image(100, 100, "assets/images/paper/base.png");
testImg.setInteractive({ pixelPerfect: true });
testImg.on("pointerup", () => {
    testImg.destroy();
});

Additional Information

I'd be willing to fix this myself in a PR, but wanted to make sure that I am using this API correctly. Are we allowed to destroy game objects directly in event handlers or MUST they be destroyed at the event of update calls? (I've had a few other issues with destroying game objects throwing errors in phaser internals, but was about to work around them in the past)

@photonstorm
Copy link
Collaborator

Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

@SachsKaylee
Copy link
Author

Works flawlessly, thank you very much.

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

No branches or pull requests

2 participants