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

Tampering with the html just after game.destroy() might cause an endless chain of error #6559

Closed
orcomarcio opened this issue Jul 25, 2023 · 3 comments

Comments

@orcomarcio
Copy link

Version

  • Phaser Version: 3.60
  • Operating system: Windows 11
  • Browser: Chrome

Description

For a few reason that are too long to explain I empty the parent of the DOM container "by hand" after calling game.destroy(). In the 3.5 it didn't give any problem, but in the 3.6 causes endless errors.
image

The main issue is this code in Phaser.Game#runDestroy
image

As you can see it checks if this.domContainer is valid, but not for this.domContainer.parentNode.
Changing the condition like this prevents the error.
image

Example Test Code

I destroy de game calling this (I tried putting false as the first argument but it still gives the error);
gameStage.destroy(true, true);

This is how I empty the parent container
mainContDiv.innerHTML = "";

I call them one after the other in the same function. I was thinking about clearing the html inside an onDestroy event, but phaser waits a bit before removing the div, so intead of closing right away you see black for a fraction of a second, something that I want to avoid.

Additional Information

@photonstorm
Copy link
Collaborator

Part of me thinks this is what you get for treating an async operation as synchronous (there is an event for a reason! and nothing stops you using a little CSS to hide the canvas immediately to avoid this 'black for a fraction'). However, it's also an easy guard to add in, so I'll consider it for 3.61 - just be aware there are potentially other things going on internally as well, that this won't cover.

@orcomarcio
Copy link
Author

orcomarcio commented Jul 31, 2023

Thanks.
I agree with you, apparently though we're not allowed to change that part of our company's framework for compatibility reasons (I proposed to use the onDestroy event).

FYI I had managed to temporarely "solve" it by doing this

game.domContainer = undefined;
game.destroy(true, true);

@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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants