Skip to content

Fix WebGL context creation on Windows, bump to 19.1.0#1388

Merged
obiot merged 4 commits intomasterfrom
fix/webgl-context-guard
Apr 16, 2026
Merged

Fix WebGL context creation on Windows, bump to 19.1.0#1388
obiot merged 4 commits intomasterfrom
fix/webgl-context-guard

Conversation

@obiot
Copy link
Copy Markdown
Member

@obiot obiot commented Apr 15, 2026

Summary

  • Change failIfMajorPerformanceCaveat default from true to false — allows WebGL context creation on machines with blocklisted GPU drivers or software renderers (Windows VMs, older Intel GPUs). Matches PixiJS and Phaser defaults.
  • Guard getSupportedCompressedTextureFormats() against null/undefined GL context — falls back to empty format list instead of crashing
  • Fix compressed textures example text rendering after Text.draw() standalone removal in 19.0

Test plan

  • Build passes
  • WebGL examples work on macOS
  • Compressed textures example works on Windows Chrome (needs colleague verification)

🤖 Generated with Claude Code

- 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>
Copilot AI review requested due to automatic review settings April 15, 2026 11:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 uses this._gl.getExtension(...), but this._gl is never defined on WebGLRenderer (only this.gl is assigned in the constructor). If gl.getExtension(...) returns null for an unsupported extension, the || this._gl.getExtension(...) branch will throw. Use gl.getExtension("WEBKIT_...") (or set this._gl = this.gl consistently) instead of referencing this._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.

Comment thread packages/melonjs/src/video/rendertarget/canvasrendertarget.js
Comment thread packages/examples/src/examples/compressedTextures/ExampleCompressedTextures.tsx Outdated
Comment thread packages/melonjs/CHANGELOG.md
obiot and others added 2 commits April 16, 2026 07:58
- Change failIfMajorPerformanceCaveat default to false in
  defaultApplicationSettings (was only changed in canvasrendertarget)
- Fix drawText: set font.pos before font.setText to render at correct position

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Tests that create a WebGL context need failIfMajorPerformanceCaveat: true
to avoid software rendering in headless CI browsers, which produces
broken contexts that fail save/restore and texture cleanup.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 16, 2026 00:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +234 to 238
if (typeof gl === "undefined" || gl === null) {
// WebGL context not available
return super.getSupportedCompressedTextureFormats();
}
supportedCompressedTextureFormats = {
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getSupportedCompressedTextureFormats() uses this._gl.getExtension(...) in the extension fallbacks, but _gl is not defined anywhere on WebGLRenderer (repo-wide search shows no assignment/definition). This will throw whenever the non-prefixed extension is unavailable (common), which defeats the intent of the new guard. Use gl.getExtension("WEBKIT_...") instead (same context) or explicitly define _gl in the constructor before calling it.

Copilot uses AI. Check for mistakes.
Comment thread packages/melonjs/tests/webgl_save_restore.spec.js
Comment thread packages/melonjs/tests/font.spec.js
Application default stays true (avoids software WebGL in CI headless
browsers which causes shader/context errors). Only the CanvasRenderTarget
internal default is false. Users can opt in with explicit setting.
Revert test-specific failIfMajorPerformanceCaveat overrides.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@obiot obiot merged commit 737c621 into master Apr 16, 2026
6 checks passed
@obiot obiot deleted the fix/webgl-context-guard branch April 16, 2026 02:47
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.

2 participants