Skip to content

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

Open
obiot wants to merge 1 commit intomasterfrom
fix/webgl-context-guard
Open

Fix WebGL context creation on Windows, bump to 19.1.0#1388
obiot wants to merge 1 commit 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 on lines 19 to 23
stencil: true,
blendMode: "normal",
failIfMajorPerformanceCaveat: true,
failIfMajorPerformanceCaveat: false,
preferWebGL1: false,
powerPreference: "default",
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.
Comment on lines +152 to +153
font.setText(text);
font.pos.set(x, y);
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

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).

Suggested change
font.setText(text);
font.pos.set(x, y);
font.pos.set(x, y);
font.setText(text);

Copilot uses AI. Check for mistakes.
Comment on lines +5 to +7
### 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

Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.
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