{"record":{"id":"49093b33db7e15d6","repo":"BabylonJS/Babylon.js","slug":"buffer-access-is-out-of-range","errorCode":null,"errorMessage":"Buffer access is out of range","messagePattern":"Buffer access is out of range","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/loaders/src/glTF/1.0/glTFLoaderUtils.ts","lineNumber":183,"sourceCode":"            case ETextureFilterType.NEAREST_MIPMAP_NEAREST:\r\n                return Texture.NEAREST_SAMPLINGMODE;\r\n            default:\r\n                return Texture.BILINEAR_SAMPLINGMODE;\r\n        }\r\n    }\r\n\r\n    public static GetBufferFromBufferView(\r\n        gltfRuntime: IGLTFRuntime,\r\n        bufferView: IGLTFBufferView,\r\n        byteOffset: number,\r\n        byteLength: number,\r\n        componentType: EComponentType\r\n    ): ArrayBufferView {\r\n        byteOffset = bufferView.byteOffset + byteOffset;\r\n\r\n        const loadedBufferView = gltfRuntime.loadedBufferViews[bufferView.buffer];\r\n        if (byteOffset + byteLength > loadedBufferView.byteLength) {\r\n            throw new Error(\"Buffer access is out of range\");\r\n        }\r\n\r\n        const buffer = loadedBufferView.buffer;\r\n        byteOffset += loadedBufferView.byteOffset;\r\n\r\n        switch (componentType) {\r\n            case EComponentType.BYTE:\r\n                return new Int8Array(buffer, byteOffset, byteLength);\r\n            case EComponentType.UNSIGNED_BYTE:\r\n                return new Uint8Array(buffer, byteOffset, byteLength);\r\n            case EComponentType.SHORT:\r\n                return new Int16Array(buffer, byteOffset, byteLength);\r\n            case EComponentType.UNSIGNED_SHORT:\r\n                return new Uint16Array(buffer, byteOffset, byteLength);\r\n            default:\r\n                return new Float32Array(buffer, byteOffset, byteLength);\r\n        }\r\n    }\r","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/loaders/src/glTF/1.0/glTFLoaderUtils.ts#L165-L201","documentation":"glTF 1.0 loader utility GetBufferFromBufferView throws this when the requested byte range (bufferView.byteOffset + byteOffset through byteOffset + byteLength) exceeds the loaded buffer view's byteLength. It means the glTF asset references more bytes than the buffer actually provides — a corrupted or malformed asset.","triggerScenarios":"Loading a glTF 1.0 file whose accessor byteOffset/byteLength/byteStride exceed the bufferView size, or whose buffer was truncated (incomplete download/embedded data shorter than declared).","commonSituations":"Hand-edited or tool-mangled glTF where byteOffsets were not recomputed; truncated .bin sidecar file; binary asset corrupted during upload/deployment; wrong buffer referenced in the JSON.","solutions":["Re-export or re-download the glTF/binary assets to ensure they are not truncated","Validate the glTF with the glTF-Validator (Khronos) to find out-of-range accessors","Check that the .bin buffer matches the JSON-declared byteLength","If hand-editing, recompute accessor byteOffset/byteLength against bufferView bounds"],"exampleFix":"// before (hand-edited glTF JSON)\n\"accessors\": [{ \"bufferView\": 0, \"byteOffset\": 512, \"count\": 10000, ... }] // exceeds bufferView\n// after: re-export from the DCC tool so offsets/count match buffer size","handlingStrategy":"validation","validationCode":"function accessorFitsBufferView(accessor, bufferView) {\n  const size = { 5120:1, 5121:1, 5122:2, 5123:2, 5125:4, 5126:4 }[accessor.componentType];\n  const comps = { SCALAR:1, VEC2:2, VEC3:3, VEC4:4, MAT4:16 }[accessor.type];\n  return accessor.byteOffset + accessor.count * comps * size <= bufferView.byteLength;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await BABYLON.SceneLoader.LoadAsync('./', 'model.gltf', engine);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Buffer access is out of range') {\n    console.error('glTF buffer/accessor out of bounds: asset is malformed or truncated');\n  } else throw e;\n}","preventionTips":["Run assets through Khronos glTF-Validator before shipping","Verify .bin/GLB byte sizes against JSON-declared byteLength after download","Never hand-edit accessor offsets; always re-export from the tool","Add integrity checks (size/hash) on downloaded binary assets"],"tags":["gltf","loader","buffer","corrupt-asset"],"backgroundTag":"buffer-out-of-range","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}