Skip to content

WebGL: extension string is available even though Emscripten doesn't implement it #20798

@kainino0x

Description

@kainino0x

Please include the following in your bug report:

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.50-git (9d830e22903a58a97e5aff79e31e05882112f8db)
clang version 18.0.0 (https://github.com/llvm/llvm-project e88a1ce0137bc14b754b86313228fdc48ba737f3)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /Users/kainino/sources/emsdk/upstream/bin

Failing command line in full:
emcc main.cpp -o index.html -g -sUSE_WEBGL2

Full link command and output with -v appended:
No build failure

Repro code: https://github.com/kainino0x/emscripten-extension-bug
Repro page: https://kai.graphics/emscripten-extension-bug/

Chrome Canary (as of 121.0.6153.0) recently enabled 4 new WebGL extensions:
EXT_clip_control
EXT_depth_clamp
EXT_polygon_offset_clamp
WEBGL_polygon_mode
https://chromiumdash.appspot.com/commit/40900b5e6698955aba32af9679519104c3bad20f

Emscripten passes through the extension strings from WebGL, but it does not actually implement the new entry points glClipControlEXT and glPolygonOffsetClampEXT. These will fail to link if you try to use them directly - but they'll return NULL if you try to get them with GetProcAddress, causing a crash in existing builds if they contain code to use these extensions:

EXT_polygon_offset_clamp was available, calling glPolygonOffsetClampEXT...
Uncaught RuntimeError: null function or function signature mismatch
    at index.wasm.__original_main (index.wasm:0x2dad)
    at index.wasm.main (index.wasm:0x2de3)
    at index.js:709:14
    at callMain (index.js:5683:15)
    at doRun (index.js:5733:23)
    at index.js:5744:7

To reproduce this make sure you have an updated Canary and EXT_polygon_offset_clamp is available on webglreport.com.
(If on Mac, you may need to switch to the Metal backend at chrome://flags/#use-angle.)

EDIT: I am going to revert these new extensions from Chrome per my analysis below. Hopefully a repro isn't really necessary but if needed, you can use an older Chromium snapshot:

Follow the Puppeteer instructions here:
https://www.chromium.org/getting-involved/download-chromium/#chrome-for-testing
Or use these snapshots:
https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Linux_x64/1229878/ (not tried)
https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Win_x64/1229878/ (not tried)
https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Mac_Arm/1229875/ (although I can't actually get this to work on my ARM mac)
https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Mac/1229878/ (nor these, though I thought they were dual-architecture binaries)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions