Repository navigation
Fix uniform index queries and accept more texImage2D sources - #4
Merged
Merged
Conversation
…names glGetIntegerv writes as many values as the pname defines, and the driver cannot know how large the destination is. The default branch of getParameter() passed a one-element Int32Array, so any array pname that is not special-cased above it overflowed the heap. GL_COMPRESSED_TEXTURE_FORMATS is the case that bit: a desktop Mesa stack reports 51 formats, so the driver wrote ~200 bytes past the end of a 4-byte buffer. The corruption landed in whatever allocated next -- usually V8 -- and surfaced as an unrelated crash much later, with backtraces pointing at the wasm compiler rather than here. Over-allocate a 64-int scratch and return the first element. Scalars are unchanged; an unlisted array pname now costs a slightly larger temporary instead of corrupting the heap. Adds getParameterArray() for callers that want the whole array. npm test: 204 passed, 0 failed.
Three fixes to WebGL2 calls that any twgl-based library hits. getUniformIndices / getActiveUniforms: argument arity mismatch The JS wrappers passed a count argument the native bindings do not take. _getUniformIndices reads (program, namesArray, outIndices) and derives the count from the array itself; _getActiveUniformsiv reads (program, indices, pname, outParams). Passing the extra count shifted every argument along, so the addon rejected the call with "Invalid argument". twgl calls both while building any program that has uniforms. texImage2D: coerce undefined/null width and height WebIDL coerces the numeric arguments, so a browser turns an undefined or null width/height into 0 and allocates an empty texture. The native binding demanded real numbers and threw "A number was expected". Allocating an empty texture this way is common: twgl's setEmptyTexture() calls exactly like this whenever a texture is created with no src and no explicit size. texImage2D: accept ImageData as a source ImageData is a valid texImage2D source per the WebGL spec. The 6-arg path only handled Canvas and Image, so it threw "Value is not one of these types". Its pixels are already RGBA in the expected layout, so they upload directly rather than going through a temp canvas, which rejects ImageData anyway. Verified with the existing suite: 204 passed, 0 failed.
monteslu
force-pushed
the
fix-uniform-queries-and-texture-sources
branch
from
September 16, 2026 01:58
ad13221 to
9ab3a45
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three fixes to WebGL2 calls that any twgl-based library hits.
getUniformIndices / getActiveUniforms: argument arity mismatch
The JS wrappers passed a count argument that the native bindings do not take:
_getUniformIndicesreads(program, namesArray, outIndices)and derives the count from the array itself, but the wrapper passed 4 arguments._getActiveUniformsivreads(program, indices, pname, outParams), but the wrapper passed 5.Every argument shifted along, so the addon rejected the call with
Invalid argument. twgl calls both while building any program that has uniforms. It reproduces in a few lines:texImage2D: coerce undefined/null width and height
WebIDL coerces the numeric arguments, so a browser turns an undefined or null width/height into 0 and allocates an empty texture. The native binding demanded real numbers and threw
A number was expected.Allocating an empty texture this way is common: twgl's
setEmptyTexture()calls exactly like this whenever a texture is created with nosrcand no explicit size.texImage2D: accept ImageData as a source
ImageDatais a validtexImage2Dsource per the WebGL spec. The 6-arg path only handled Canvas and Image, so it threwValue is not one of these types.Its pixels are already RGBA in the expected layout, so they now upload directly instead of routing through a temp canvas, which rejects ImageData anyway. That is also one less copy.
Verification
Existing suite: 204 passed, 0 failed.