{"record":{"id":"3d5fd878fb46d4a5","repo":"phaserjs/phaser","slug":"invalid-buffer-type-for-array-buffer","errorCode":null,"errorMessage":"Invalid buffer type for ARRAY_BUFFER","messagePattern":"Invalid buffer type for ARRAY_BUFFER","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/renderer/webgl/wrappers/WebGLGlobalWrapper.js","lineNumber":213,"sourceCode":"    /**\n     * Updates the array buffer (ARRAY_BUFFER) binding state. This binds the\n     * vertex buffer object used to supply vertex attribute data to the GPU.\n     *\n     * @method Phaser.Renderer.WebGL.Wrappers.WebGLGlobalWrapper#updateBindingsArrayBuffer\n     * @since 4.0.0\n     * @param {Phaser.Types.Renderer.WebGL.WebGLGlobalParameters} state - The state to set.\n     * @param {boolean} [force=false] - If `true`, the state will be set regardless of the current state.\n     */\n    updateBindingsArrayBuffer: function (state, force)\n    {\n        var arrayBuffer = state.bindings.arrayBuffer;\n        var gl = this.renderer.gl;\n        if (\n            arrayBuffer !== null &&\n            arrayBuffer.bufferType !== gl.ARRAY_BUFFER\n        )\n        {\n            throw new Error('Invalid buffer type for ARRAY_BUFFER');\n        }\n\n        var different = arrayBuffer !== this.state.bindings.arrayBuffer;\n\n        if (different)\n        {\n            this.state.bindings.arrayBuffer = arrayBuffer;\n        }\n        if (different || force)\n        {\n            var webGLBuffer = arrayBuffer ? arrayBuffer.webGLBuffer : null;\n            gl.bindBuffer(gl.ARRAY_BUFFER, webGLBuffer);\n        }\n    },\n\n    /**\n     * Updates the index array buffer state.\n     *","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/phaserjs/phaser/blob/41be1e462bc600064e498cba370bfa8c5c055a22/src/renderer/webgl/wrappers/WebGLGlobalWrapper.js#L195-L231","documentation":"Thrown by WebGLGlobalWrapper.updateBindingsArrayBuffer when the buffer object bound as ARRAY_BUFFER has a bufferType that is not gl.ARRAY_BUFFER. The global state wrapper type-checks buffer bindings to catch the classic mistake of binding an index/element buffer to a vertex slot (and vice versa), which would otherwise corrupt GPU state silently.","triggerScenarios":"Passing a WebGLBufferWrapper whose bufferType is gl.ELEMENT_ARRAY_BUFFER (or anything other than ARRAY_BUFFER) into the arrayBuffer slot of a state update; creating a buffer with createIndexBuffer and binding it as a vertex buffer.","commonSituations":"Misusing renderer.createIndexBuffer output as a vertex buffer; hand-rolling buffer binding code that swaps array/element buffers; a bug in a custom render node that binds the wrong wrapper object.","solutions":["Use renderer.createVertexBuffer (bufferType = ARRAY_BUFFER) for vertex data and bind it to arrayBuffer.","Inspect the wrapper's bufferType before binding: if (buf.bufferType === gl.ARRAY_BUFFER).","Do not reuse an index buffer as a vertex buffer; allocate a correctly-typed buffer.","Trace where the buffer object was created and confirm the intended usage."],"exampleFix":"// before\nconst buf = renderer.createIndexBuffer(new Uint16Array(verts));\nglWrapper.updateBindingsArrayBuffer({ bindings: { arrayBuffer: buf } }); // throws\n\n// after\nconst buf = renderer.createVertexBuffer(new Float32Array(verts));\nglWrapper.updateBindingsArrayBuffer({ bindings: { arrayBuffer: buf } });","handlingStrategy":"type-guard","validationCode":"function bindArrayBuffer(glWrapper, gl, buf) {\n  if (buf && buf.bufferType !== gl.ARRAY_BUFFER) {\n    throw new TypeError('Expected ARRAY_BUFFER-typed wrapper');\n  }\n  glWrapper.updateBindingsArrayBuffer({ bindings: { arrayBuffer: buf } });\n}","typeGuard":"function isArrayBufferWrapper(buf, gl) { return buf == null || buf.bufferType === gl.ARRAY_BUFFER; }","tryCatchPattern":null,"preventionTips":["Always create vertex buffers with createVertexBuffer.","Keep vertex and index buffers in separate, clearly-named variables.","Add a debug assert on bufferType before binding."],"tags":["renderer","webgl","buffer","webgl-wrapper","phaser4"],"backgroundTag":null,"analyzedSha":"41be1e462bc600064e498cba370bfa8c5c055a22","analyzedAt":"2026-08-13T04:23:39.729Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}