{"record":{"id":"ca10e9e48ae991c1","repo":"mrdoob/three.js","slug":"three-bufferattribute-array-should-be-a-typed-arr","errorCode":null,"errorMessage":"THREE.BufferAttribute: array should be a Typed Array.","messagePattern":"THREE\\.BufferAttribute: array should be a Typed Array\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/core/BufferAttribute.js","lineNumber":36,"sourceCode":" * When working with vector-like data, the `fromBufferAttribute( attribute, index )`\n * helper methods on vector and color class might be helpful. E.g. {@link Vector3#fromBufferAttribute}.\n */\nclass BufferAttribute extends EventDispatcher {\n\n\t/**\n\t * Constructs a new buffer attribute.\n\t *\n\t * @param {TypedArray} array - The array holding the attribute data.\n\t * @param {number} itemSize - The item size.\n\t * @param {boolean} [normalized=false] - Whether the data are normalized or not.\n\t */\n\tconstructor( array, itemSize, normalized = false ) {\n\n\t\tsuper();\n\n\t\tif ( Array.isArray( array ) ) {\n\n\t\t\tthrow new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );\n\n\t\t}\n\n\t\t/**\n\t\t * This flag can be used for type testing.\n\t\t *\n\t\t * @type {boolean}\n\t\t * @readonly\n\t\t * @default true\n\t\t */\n\t\tthis.isBufferAttribute = true;\n\n\t\t/**\n\t\t * The ID of the buffer attribute.\n\t\t *\n\t\t * @name BufferAttribute#id\n\t\t * @type {number}\n\t\t * @readonly","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/mrdoob/three.js/blob/da05705fa31f02710c19772a2aa70c7454807f0c/src/core/BufferAttribute.js#L18-L54","documentation":"The BufferAttribute constructor throws a TypeError when its first argument is a plain JavaScript Array. BufferAttribute requires a TypedArray (e.g. Float32Array, Uint16Array) because GPU buffers need contiguous, fixed-width binary data; a regular Array is a boxed, heterogeneous JS object and cannot be uploaded to the GPU.","triggerScenarios":"Constructing new THREE.BufferAttribute([x, y, z, ...], itemSize) with a literal array or an array built via [].push(). Also wrapping data produced by JSON.parse or CSV parsing (which yield normal Arrays) without converting to a TypedArray.","commonSituations":"Beginners building geometry from hand-written coordinate lists. Loading numeric data from JSON/text and passing it straight to geometry.setAttribute(). Porting code from libraries that return plain arrays. Using BufferAttribute where a Float32BufferAttribute convenience subclass was intended.","solutions":["Wrap the array in a TypedArray matching your data type, e.g. new Float32Array([...]) for positions/normals/uv, new Uint16Array or Uint32Array for indices.","Use the typed convenience constructors: new THREE.Float32BufferAttribute(array, itemSize) or Uint16/Uint32/Int8 equivalents, which accept a plain array and convert it for you.","When parsing external data, convert once: const typed = new Float32Array(parsedArray) before creating the attribute.","Confirm itemSize matches the component count (2 for uv, 3 for position/normal) so the TypedArray length is itemSize * vertexCount."],"exampleFix":"// before\nconst attr = new THREE.BufferAttribute([0,0,0, 1,0,0], 3); // throws TypeError\n\n// after\nconst attr = new THREE.BufferAttribute(new Float32Array([0,0,0, 1,0,0]), 3);\n// or use the convenience subclass that accepts a plain array\nconst attr2 = new THREE.Float32BufferAttribute([0,0,0, 1,0,0], 3);","handlingStrategy":"type-guard","validationCode":"function toTypedArray(array, Ctor = Float32Array) {\n  if (ArrayBuffer.isView(array) && !Array.isArray(array)) return array;\n  if (Array.isArray(array)) return new Ctor(array);\n  throw new TypeError('Expected a TypedArray or plain array');\n}\n\nconst attr = new THREE.BufferAttribute(toTypedArray(data), itemSize);","typeGuard":"function isTypedArray(value) {\n  return value != null\n    && typeof value === 'object'\n    && ArrayBuffer.isView(value)\n    && !(value instanceof DataView);\n}\n\n// usage\nif (!isTypedArray(array)) array = new Float32Array(array);","tryCatchPattern":null,"preventionTips":["Prefer the typed convenience constructors (Float32BufferAttribute, Uint16BufferAttribute).","Always wrap parsed JSON arrays in a TypedArray before creating attributes.","Run a quick ArrayBuffer.isView() check on data sourced from external parsing."],"tags":["threejs","typed-array","bufferattribute","geometry","beginner"],"backgroundTag":null,"analyzedSha":"da05705fa31f02710c19772a2aa70c7454807f0c","analyzedAt":"2026-08-12T22:51:37.160Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}