BabylonJS/Babylon.js · error · Error
Buffer access is out of range
Error message
Buffer access is out of range
What it means
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.
Source
Thrown at packages/dev/loaders/src/glTF/1.0/glTFLoaderUtils.ts:183
case ETextureFilterType.NEAREST_MIPMAP_NEAREST:
return Texture.NEAREST_SAMPLINGMODE;
default:
return Texture.BILINEAR_SAMPLINGMODE;
}
}
public static GetBufferFromBufferView(
gltfRuntime: IGLTFRuntime,
bufferView: IGLTFBufferView,
byteOffset: number,
byteLength: number,
componentType: EComponentType
): ArrayBufferView {
byteOffset = bufferView.byteOffset + byteOffset;
const loadedBufferView = gltfRuntime.loadedBufferViews[bufferView.buffer];
if (byteOffset + byteLength > loadedBufferView.byteLength) {
throw new Error("Buffer access is out of range");
}
const buffer = loadedBufferView.buffer;
byteOffset += loadedBufferView.byteOffset;
switch (componentType) {
case EComponentType.BYTE:
return new Int8Array(buffer, byteOffset, byteLength);
case EComponentType.UNSIGNED_BYTE:
return new Uint8Array(buffer, byteOffset, byteLength);
case EComponentType.SHORT:
return new Int16Array(buffer, byteOffset, byteLength);
case EComponentType.UNSIGNED_SHORT:
return new Uint16Array(buffer, byteOffset, byteLength);
default:
return new Float32Array(buffer, byteOffset, byteLength);
}
}
View on GitHub (pinned to 0592b347b8)
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
Example fix
// before (hand-edited glTF JSON)
"accessors": [{ "bufferView": 0, "byteOffset": 512, "count": 10000, ... }] // exceeds bufferView
// after: re-export from the DCC tool so offsets/count match buffer size Defensive patterns
Strategy: validation
Validate before calling
function accessorFitsBufferView(accessor, bufferView) {
const size = { 5120:1, 5121:1, 5122:2, 5123:2, 5125:4, 5126:4 }[accessor.componentType];
const comps = { SCALAR:1, VEC2:2, VEC3:3, VEC4:4, MAT4:16 }[accessor.type];
return accessor.byteOffset + accessor.count * comps * size <= bufferView.byteLength;
} Try / catch
try {
await BABYLON.SceneLoader.LoadAsync('./', 'model.gltf', engine);
} catch (e) {
if (e instanceof Error && e.message === 'Buffer access is out of range') {
console.error('glTF buffer/accessor out of bounds: asset is malformed or truncated');
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- ${context}: ${error.message}
- ${extensionContext}: Gaussian splatting primitives must use
- ${extensionContext}: Gaussian splatting primitive is missing
- ${context}: Uri is missing or the binary glTF is missing its
- ${context}: Failed to find index (${index})
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/49093b33db7e15d6.
Report an issue: GitHub.