emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.83k stars 3.31k forks source link

Type error in `emscripten_webgl_do_create_context` #22943

Open JoeOsborn opened 2 hours ago

JoeOsborn commented 2 hours ago

If client code asks for explicit swap control, a transferred canvas record is obtained from GL.offscreenCanvases, but then that record (and not the underlying OffscreenCanvas) is passed through to GL.createContext, which expects an actual offscreen canvas. The fix is to add ....offscreenCanvas || ....canvas on the end of line 174, or else to change the code of emscripten_webgl_do_create_context to unpack the canvas.

https://github.com/emscripten-core/emscripten/blob/5203d0805881ac4daf841e08cb320b1885b01cfb/src/library_html5_webgl.js#L174

JoeOsborn commented 2 hours ago

findCanvasEventTarget has a similar bug, in that it will sometimes return a key from GL.offscreenCanvases, sometimes return an element from GL.offscreenCanvases, and sometimes return an arbitrary HTML element. It should always return something of a reasonable type, whether or not offscreen canvas support is enabled. (In particular it does not make sense for it to sometimes return an element of GL.offscreenCanvases and sometimes an HTML element.)