regl-project / regl

👑 Functional WebGL
https://regl-project.github.io/
MIT License
5.24k stars 323 forks source link

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

Open nsf opened 6 months ago

nsf commented 6 months ago

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. https://github.com/regl-project/regl/blob/63cd83c6ee1d8619bd731f76dc1fff88ddffc436/lib/elements.js#L79-L97

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. :disappointed: