phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
36.95k stars 7.08k forks source link

Phaser3 runs abnormally in webview #6861

Closed cy920820 closed 2 months ago

cy920820 commented 2 months ago

Version

Description

Embedding Phaser3 into the Android webview, the game runs normally when opened for the first time, but does not run when opened for the second time

When I was debugging with Chrome, I clicked on manually refreshing the webview page for the game to run normally, and there were no error messages on the console

Example Test Code

Additional Information

greptile-apps[bot] commented 2 months ago

For internal use only

The issue might be related to WebGL context loss and restoration. Phaser 3.80 introduced features to handle WebGL context loss. Ensure you are listening for the LOSE_WEBGL and RESTORE_WEBGL events in your game. Refer to the WebGL Context Restore documentation for implementation details. Example:

this.game.renderer.on('LOST', () => {
  console.warn('WebGL context lost');
});

this.game.renderer.on('RESTORED', () => {
  console.log('WebGL context restored');
});

References

/changelog/3.80/CHANGELOG-v3.80.md /changelog/3.80/WebGLContextRestore.md

#### About Greptile This response provides a starting point for your research, not a precise solution. Help us improve! Please leave a ๐Ÿ‘ if this is helpful and ๐Ÿ‘Ž if it is irrelevant. [Ask Greptile](https://app.greptile.com/chat/github/phaserjs/phaser/master) ยท [Edit Issue Bot Settings](https://app.greptile.com/apps/github)
cy920820 commented 2 months ago

Why can it run normally the first time, but not the second time

photonstorm commented 2 months ago

There's nothing we can do with this level of information I'm afraid. The issue is not Phaser inside a Webview. Lots of users wrap it in that way. So it has to be something specific about the game code, or the wrapper code. Confirm this for yourself by creating a base Phaser test that has nothing but a single image in it. Does that also fail to run a second time? If so, check how the view is being re-run. There are various events within Phaser you can listen for, especially as part of the boot process, to know at which stage it's failing. Debugging is going to be the key here.