Skip to content

Fall back to the Canvas renderer when WebGL context creation fails under AUTO - #7371

Open
pavle-goloskokovic wants to merge 2 commits into
phaserjs:masterfrom
pavle-goloskokovic:v4/webgl-fallback
Open

Fall back to the Canvas renderer when WebGL context creation fails under AUTO#7371
pavle-goloskokovic wants to merge 2 commits into
phaserjs:masterfrom
pavle-goloskokovic:v4/webgl-fallback

Conversation

@pavle-goloskokovic

Copy link
Copy Markdown
Contributor

This PR

  • Adds a new feature

Describe the changes below:

When type: Phaser.AUTO is used, CreateRenderer picks WebGL if Features.webGL
is true. That feature check can pass while the actual context creation still fails:
blacklisted GPUs, devices that hit their WebGL context limit, some embedded webviews,
and background-throttled tabs on game portals. Today new WebGLRenderer() throws
"WebGL unsupported" in that case and the game never boots, even though the Canvas
renderer is compiled in and would work.

With this change, if AUTO was requested and the WebGL renderer throws during
construction, CreateRenderer switches config.renderType to CANVAS and creates a
CanvasRenderer instead. The original error is re-dispatched as an error event on
window, with ". Falling back to CanvasRenderer" appended to its message, so error
monitoring still records that the fallback happened.

An explicit type: Phaser.WEBGL is unaffected and keeps throwing, so anyone who
requires WebGL can still fail loudly.

Also adds tests/core/CreateRenderer.test.js covering the fallback, the dispatched
error, and the explicit-WEBGL rethrow. Note: like the other Game tests it loads
dist/phaser.js, so the two fallback cases only pass against a bundle rebuilt from
this branch.

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.

1 participant