Repository navigation
Conversation
`Module['ctx']` was an undocumented legacy property populated by WebGL context activation (`libwebgl.js`, `libhtml5_webgl.js`) and main-canvas context creation (`Browser.createContext` in `libbrowser.js`). Because `GL.makeContextCurrent` unconditionally assigned to the quoted `Module['ctx']` property, Closure Compiler could not dead-strip it, adding a few bytes to every WebGL build. - Stop assigning `Module['ctx']` in `libwebgl.js` and `libhtml5_webgl.js`. - Store the main-canvas context on internal `Browser.ctx` instead of `Module['ctx']` across `libbrowser.js`, `libglfw.js`, and `libglut.js`. - Update the `ASSERTIONS`-mode `EM_TIMING_SETTIMEOUT` warning in `libeventloop.js` to check `GLctx` and `Browser.ctx`. - Drop the dead `Module['ctx']` fallback in `src/cpuprofiler.js` (left over from `--proxy-to-worker`, removed in emscripten-core#25645).
There was a problem hiding this comment.
Code Review
This pull request removes the undocumented Module['ctx'] property, replacing its usage with Browser.ctx or GLctx across various library files, and updates the changelog and test code sizes. A review comment points out a potential issue in src/lib/libbrowser.js where a cached 2D context could be incorrectly returned instead of creating a WebGL context, and suggests checking Browser.useWebGL to prevent this.
|
|
||
| createContext(/** @type {HTMLCanvasElement} */ canvas, useWebGL, setInModule, webGLContextAttributes) { | ||
| if (useWebGL && Module['ctx'] && canvas == Browser.getCanvas()) return Module['ctx']; // no need to recreate GL context if it's already been created for this canvas. | ||
| if (useWebGL && Browser.ctx && canvas == Browser.getCanvas()) return Browser.ctx; // no need to recreate GL context if it's already been created for this canvas. |
There was a problem hiding this comment.
If a 2D context was previously created on the canvas, Browser.ctx will be populated, but Browser.useWebGL will be false. If createContext is subsequently called with useWebGL = true on the same canvas, the current check will incorrectly return the 2D context instead of attempting to create a WebGL context. Checking Browser.useWebGL ensures that we only return the cached context if it matches the requested WebGL state.
if (useWebGL && Browser.useWebGL && Browser.ctx && canvas == Browser.getCanvas()) return Browser.ctx; // no need to recreate GL context if it's already been created for this canvas.
Module['ctx']was an undocumented legacy property populated by WebGL context activation (libwebgl.js,libhtml5_webgl.js) and main-canvas context creation (Browser.createContextinlibbrowser.js). BecauseGL.makeContextCurrentunconditionally assigned to the quotedModule['ctx']property, Closure Compiler could not dead-strip it, adding a few bytes to every WebGL build.Module['ctx']inlibwebgl.jsandlibhtml5_webgl.js.Browser.ctxinstead ofModule['ctx']acrosslibbrowser.js,libglfw.js, andlibglut.js.ASSERTIONS-modeEM_TIMING_SETTIMEOUTwarning inlibeventloop.jsto checkGLctxandBrowser.ctx.Module['ctx']fallback insrc/cpuprofiler.js(left over from--proxy-to-worker, removed in Remove --proxy-to-worker/-sPROXY_TO_WORKER #25645).