Skip to content

[webgl] Raise GL_INVALID_OPERATION from glUniform*() with an invalid location - #28359

Open
juj wants to merge 1 commit into
emscripten-core:mainfrom
juj:glUniform_invalid_location_error
Open

juj wants to merge 1 commit into
emscripten-core:mainfrom
juj:glUniform_invalid_location_error

Conversation

@juj

@juj juj commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

Record GL_INVALID_OPERATION when the location passed to glUniform*() does not resolve to a uniform location of the current program and is not -1.

Fixes: #16367

…location

WebGL represents uniform locations as opaque WebGLUniformLocation objects,
so Emscripten maintains a per-program table that maps the integer locations
of GLES to them. That table is populated lazily on the first call to
glGetUniformLocation(). If glUniform*() was called with an integer that is
not in the table, e.g. a hardcoded location that was never acquired from
glGetUniformLocation(), the lookup produced `undefined`, which WebGL
silently ignores. In native GLES such a call generates GL_INVALID_OPERATION,
which made this kind of bug hard to notice when porting.

Record GL_INVALID_OPERATION when the location passed to glUniform*() does
not resolve to a uniform location of the current program and is not -1.

The error is not raised in -sGL_EXPLICIT_UNIFORM_LOCATION builds: there a
call that uses the explicit layout(location=x) of a uniform that the linker
deemed inactive must be silently ignored (ARB_explicit_uniform_location,
issue 4), and the locations taken up by inactive uniforms are not tracked.

Fixes: emscripten-core#16367

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@juj juj added the GL label Nov 21, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Behavioral difference in glUniform functions

1 participant