From 136a3ea156c361822284feb7e43906baeb9a9951 Mon Sep 17 00:00:00 2001 From: Konstantin Timoshenko Date: Fri, 17 Nov 2023 11:50:24 +0300 Subject: [PATCH] WebGLAttributes: Strict buffer size check when updating data. (#27188) * Update WebGLAttributes.js Strict check for buffer size while upload.. * fix: lint, pads * Update WebGLAttributes.js Implement the check even more strict. Clarify error message. * Update WebGLAttributes.js * Update WebGLAttributes.js Fix typo. --------- Co-authored-by: Michael Herzog --- src/renderers/webgl/WebGLAttributes.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/renderers/webgl/WebGLAttributes.js b/src/renderers/webgl/WebGLAttributes.js index 6ff4e6ebad277d..fc52e617448d6f 100644 --- a/src/renderers/webgl/WebGLAttributes.js +++ b/src/renderers/webgl/WebGLAttributes.js @@ -8,6 +8,7 @@ function WebGLAttributes( gl, capabilities ) { const array = attribute.array; const usage = attribute.usage; + const size = array.byteLength; const buffer = gl.createBuffer(); @@ -76,7 +77,8 @@ function WebGLAttributes( gl, capabilities ) { buffer: buffer, type: type, bytesPerElement: array.BYTES_PER_ELEMENT, - version: attribute.version + version: attribute.version, + size: size }; } @@ -199,6 +201,12 @@ function WebGLAttributes( gl, capabilities ) { } else if ( data.version < attribute.version ) { + if ( data.size !== attribute.array.byteLength ) { + + throw new Error( 'THREE.WebGLAttributes: The size of the buffer attribute\'s array buffer does not match the original size. Resizing buffer attributes is not supported.' ); + + } + updateBuffer( data.buffer, attribute, bufferType ); data.version = attribute.version;