Fix WebGL context creation on Windows, bump to 19.1.0#1388
Fix WebGL context creation on Windows, bump to 19.1.0#1388
Conversation
- Change failIfMajorPerformanceCaveat default to false — allows WebGL on machines with blocklisted GPU drivers, matching PixiJS/Phaser - Guard getSupportedCompressedTextureFormats() against null GL context - Fix compressed textures example text rendering (Text.draw standalone removed in 19.0) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Updates melonJS WebGL initialization and compressed texture handling to improve context creation reliability (notably on Windows) and to fix the compressed textures example rendering after the 19.0 text API change.
Changes:
- Adjust WebGL context creation defaults (
failIfMajorPerformanceCaveat) and document the change in the changelog. - Add a null/undefined WebGL context guard in
WebGLRenderer.getSupportedCompressedTextureFormats(). - Update the compressed textures example to the
setText()+preDraw()/draw()/postDraw()usage pattern, and bump package version to 19.1.0.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/melonjs/src/video/webgl/webgl_renderer.js | Adds a guard for missing GL context in compressed texture format detection. |
| packages/melonjs/src/video/rendertarget/canvasrendertarget.js | Changes default WebGL context attribute failIfMajorPerformanceCaveat to false. |
| packages/melonjs/package.json | Bumps melonjs package version to 19.1.0. |
| packages/melonjs/CHANGELOG.md | Adds 19.1.0 changelog entry describing the WebGL and example fixes. |
| packages/examples/src/examples/compressedTextures/ExampleCompressedTextures.tsx | Refactors text rendering to the newer Text rendering workflow. |
Comments suppressed due to low confidence (1)
packages/melonjs/src/video/webgl/webgl_renderer.js:241
getSupportedCompressedTextureFormats()still risks a crash because it usesthis._gl.getExtension(...), butthis._glis never defined onWebGLRenderer(onlythis.glis assigned in the constructor). Ifgl.getExtension(...)returns null for an unsupported extension, the|| this._gl.getExtension(...)branch will throw. Usegl.getExtension("WEBKIT_...")(or setthis._gl = this.glconsistently) instead of referencingthis._gl.
}
supportedCompressedTextureFormats = {
astc:
gl.getExtension("WEBGL_compressed_texture_astc") ||
this._gl.getExtension("WEBKIT_WEBGL_compressed_texture_astc"),
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| stencil: true, | ||
| blendMode: "normal", | ||
| failIfMajorPerformanceCaveat: true, | ||
| failIfMajorPerformanceCaveat: false, | ||
| preferWebGL1: false, | ||
| powerPreference: "default", |
There was a problem hiding this comment.
Changing defaultAttributes.failIfMajorPerformanceCaveat here may not actually change the engine-wide default for WebGL context creation, because video.init()/Application.init() merge in defaultApplicationSettings.failIfMajorPerformanceCaveat (currently true) and pass it into CanvasRenderTarget. If the goal is to change the default behavior for apps, the default should be updated at the application settings level as well (or this changelog entry will be misleading).
| font.setText(text); | ||
| font.pos.set(x, y); |
There was a problem hiding this comment.
Text.setText() uses the current Text.pos to render into its internal canvas (see Text.setText() implementation). In drawText, setText(text) is called before font.pos.set(x, y), so the rendered text will be positioned using the previous call's coordinates (and then reused with the new coordinates), causing incorrect placement when the same Text instance is reused. Set font.pos before calling font.setText(...) (or avoid reusing the same Text instance for multiple positions without re-rendering).
| font.setText(text); | |
| font.pos.set(x, y); | |
| font.pos.set(x, y); | |
| font.setText(text); |
| ### Changed | ||
| - WebGL: `failIfMajorPerformanceCaveat` default changed from `true` to `false` — allows WebGL context creation on machines with blocklisted GPU drivers or software renderers, matching PixiJS and Phaser behavior | ||
|
|
There was a problem hiding this comment.
The changelog states the default failIfMajorPerformanceCaveat was changed from true to false, but in the current codebase the effective default used by video.init()/Application.init() still comes from defaultApplicationSettings.failIfMajorPerformanceCaveat (which is true). Either update the application defaults accordingly or adjust this changelog entry to describe what default was actually changed (e.g. only CanvasRenderTarget's internal defaults).
Summary
failIfMajorPerformanceCaveatdefault fromtruetofalse— allows WebGL context creation on machines with blocklisted GPU drivers or software renderers (Windows VMs, older Intel GPUs). Matches PixiJS and Phaser defaults.getSupportedCompressedTextureFormats()against null/undefined GL context — falls back to empty format list instead of crashingText.draw()standalone removal in 19.0Test plan
🤖 Generated with Claude Code