Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid buffer dtype when initializing regl.elements with no data #672

Open
nsf opened this issue Apr 25, 2024 · 0 comments
Open

Invalid buffer dtype when initializing regl.elements with no data #672

nsf opened this issue Apr 25, 2024 · 0 comments

Comments

@nsf
Copy link

nsf commented Apr 25, 2024

On line 97 in the code the "dtype" variable is used, which is always undefined on that else branch, as it was declared on line 79 and never initialized. I would guess maybe it was meant to be "type" function argument instead.

regl/lib/elements.js

Lines 79 to 97 in 63cd83c

var dtype
if (data) {
var predictedType = type
if (!type && (
!isTypedArray(data) ||
(isNDArrayLike(data) && !isTypedArray(data.data)))) {
predictedType = extensions.oes_element_index_uint
? GL_UNSIGNED_INT
: GL_UNSIGNED_SHORT
}
bufferState._initBuffer(
elements.buffer,
data,
usage,
predictedType,
3)
} else {
gl.bufferData(GL_ELEMENT_ARRAY_BUFFER, byteLength, usage)
elements.buffer.dtype = dtype || GL_UNSIGNED_BYTE

In other words the fix would be to do:

elements.buffer.dtype = type || GL_UNSIGNED_BYTE

on line 97, but I'm not sure.

This breaks the code if you init elements buffer with no data and the buffer type is uint16 or uint32. Because later subdata calls might allocate a wrong typed buffer from the pool and such.

P.S. TypeScript is the way to catch bugs like these, but I guess it's too late for regl. 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant