Skip to content

[webgl] Raise GL_INVALID_VALUE from an out of range vertex attribute index in -sFULL_ES2 - #28360

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

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

Conversation

@juj

@juj juj commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

Fix calling glEnableVertexAttribArray(), glDisableVertexAttribArray(), glVertexAttribPointer() or glVertexAttribIPointer() with an invalid attribute index to record a GL_INVALID_VALUE when -sFULL_ES2 is active.

Fixes: #14589

… -sFULL_ES2

Fixes: emscripten-core#14589

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@juj juj added the GL label Nov 21, 2026
Comment thread src/lib/libwebgl.js
err(`GL_INVALID_VALUE in glEnableVertexAttribArray(index=${index}): index must be in the range 0 <= index < GL_MAX_VERTEX_ATTRIBS (${GL.currentContext.maxVertexAttribs})!`);
#endif
GL.recordError(GL_INVALID_VALUE);
return;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should the GL_TRACK_ERRORS just wrao the call to recordError?

i.e. My understanding is that turning on or off GL_TRACK_ERRORS doesn't effect whether a given call will crash or not, just whether or not glGetError will report the errors?

So maybe we should still return early if cb is missing here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Should the GL_TRACK_ERRORS just wrao the call to recordError?

That would be nice if we did require Closure compiler.. but for example Unity is not currently able to use it, so there would be tons of GL.recordError()s still left behind.

My understanding is that turning on or off GL_TRACK_ERRORS doesn't effect whether a given call will crash or not, just whether or not glGetError will report the errors?

GL_TRACK_ERRORS=1 would be that "I want benign failures" mode, and GL_TRACK_ERRORS=0 would be a "I've tested my code to not need all that pedantic error tracking" mode.

So in the GL_TRACK_ERRORS=0 mode, we'd generally assume that user doesn't run into these types of errors in the first place, so a if (!cb) return; would then be dead code.

Comment thread test/test_browser.py
'full_es2': (['-sFULL_ES2'],),
'full_es2_assertions': (['-sFULL_ES2', '-sGL_ASSERTIONS'],),
'full_es3': (['-sFULL_ES3', '-DTEST_WEBGL2'],),
'full_es3_assertions': (['-sFULL_ES3', '-DTEST_WEBGL2', '-sGL_ASSERTIONS'],),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we check the -sGL_TRACK_ERRORS=0 too and maybe sure we don't just crash/trap in that case?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think it's fine to throw an exception in that case. We do have other locations that use GL_TRACK_ERRORS like that, assuming that the errors don't occur in the first place.

glDisableVertexAttribArray(max_vertex_attribs - 1);
assert(glGetError() == GL_NO_ERROR);

printf("Test passed!\n");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This test program seem fairly involved for something that is just checking if a given call errors on a bad index.

Can it be simplified? Maybe just a few lines of code and achieve the same result?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We could test just bad API calls before compiling a program, but then it would be only testing a scenario where user doesn't even have a valid program set up. It does seem more robust to actually test that having a valid program, and then asking for invalid indices in the code.

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.

glGetAttribLocation produces exception in WebGL 2.0

2 participants