Explorar o código

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 <[email protected]>
Konstantin Timoshenko hai 1 ano
pai
achega
b67767cade
Modificáronse 1 ficheiros con 9 adicións e 1 borrados
  1. 9 1
      src/renderers/webgl/WebGLAttributes.js

+ 9 - 1
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;