phaser icon indicating copy to clipboard operation
phaser copied to clipboard

Allow overriding `contextRestoredHandler` in WebGLRenderer so we can control when a restore is called

Open yaustar opened this issue 2 months ago • 0 comments

At the moment, context restore in Phaser happens when the browser signals it has been restored. We would like to control when this happens so that we can try to increase the chances that the context stays restored.

For example, we see that context losses mostly happen when the tab is in background and for some situations, it would restore only to immediately lose it again.

We would like to try to restore the Phaser WebGLRenderer when the tab is next active instead so it only happens once and perhaps the browser will prioritise resources to it now that it is focused.

The side effect is that errors can be thrown from Phaser during the restore process that we would like to try/catch and track for analytics and that's not possible with the current restore process.

As a potential PR, I was thinking about wrapping the webglcontextrestored and webglcontextlost event listeners in private functions that internally call contextRestoredHandler / contextLostHandler instead of it being the listener directly. Maybe even separate the renderer restore logic into a separate function so that it could be called by custom overrides.

yaustar avatar Apr 18 '24 11:04 yaustar