BabylonJS/Babylon.js · error

Buffer data is not available

Error message

Buffer data is not available

What it means

This error is thrown by the glTF 2.0 exporter when serializing mesh geometry that references a GPU buffer. The exporter needs the CPU-side data of the buffer (via buffer.getData()) to embed it in the exported glTF, but the buffer has no accessible data (e.g. it is GPU-only/updatable=false, was never populated on CPU, or was already released). The library throws rather than exporting a mesh with missing vertex data.

Source

Thrown at packages/dev/serializers/src/glTF/2.0/glTFExporter.ts:1027

            this._collectBuffers(babylonChildNode, bufferToVertexBuffersMap, vertexBufferToMeshesMap, morphTargetsToMeshesMap, state);
        }
    }

    private _exportBuffers(babylonRootNodes: Node[], state: ExporterState): void {
        const bufferToVertexBuffersMap = new Map<Buffer, VertexBuffer[]>();
        const vertexBufferToMeshesMap = new Map<VertexBuffer, AbstractMesh[]>();
        const morphTargetsMeshesMap = new Map<MorphTarget, AbstractMesh[]>();

        for (const babylonNode of babylonRootNodes) {
            this._collectBuffers(babylonNode, bufferToVertexBuffersMap, vertexBufferToMeshesMap, morphTargetsMeshesMap, state);
        }

        const buffers = Array.from(bufferToVertexBuffersMap.keys());

        for (const buffer of buffers) {
            const data = buffer.getData();
            if (!data) {
                throw new Error("Buffer data is not available");
            }

            const vertexBuffers = bufferToVertexBuffersMap.get(buffer);

            if (!vertexBuffers) {
                continue;
            }

            const byteStride = vertexBuffers[0].byteStride;
            if (vertexBuffers.some((vertexBuffer) => vertexBuffer.byteStride !== byteStride)) {
                throw new Error("Vertex buffers pointing to the same buffer must have the same byte stride");
            }

            const bytes = DataArrayToUint8Array(data).slice();

            // Apply normalizations and color corrections to buffer data in-place.
            for (const vertexBuffer of vertexBuffers) {
                const meshes = vertexBufferToMeshesMap.get(vertexBuffer)!;

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Ensure all vertex buffers hold CPU data before exporting: recreate buffers with updatable=true or keep the source typed array so getData() returns data
  2. If meshes were loaded and CPU data was dropped, re-load the assets (or enable keepData/retained CPU copies in the loader) before exporting
  3. Check for disposed geometry: verify buffer.isDisposed()/mesh.geometry before export and rebuild or clone meshes (mesh.clone typically recreates CPU data)
  4. Catch the error and skip/export only meshes with available data

Example fix

// before
const vertexData = new VertexBuffer(engine, positions, VertexBuffer.PositionKind, false); // data may be GPU-only
// after
const vertexData = new VertexBuffer(engine, positions, VertexBuffer.PositionKind, true); // keep CPU copy so getData() returns data for glTF export
Defensive patterns

Strategy: validation

Validate before calling

function canExportBuffer(buffer: { getData(): Nullable<ArrayBufferView> }): boolean {
    return !!buffer.getData();
}
// before export: verify every mesh's vertex buffers have CPU data
const ready = mesh.geometrybuffers.every((b) => b.getData() != null);

Type guard

function hasBufferData(b: IBuffer): b is IBuffer & { getData(): ArrayBufferView } {
    return b.getData() != null;
}

Try / catch

try {
    await GLTF2Export.GLTFAsync(scene, "scene");
} catch (e) {
    if (e instanceof Error && e.message === "Buffer data is not available") {
        // rebuild CPU-side data or skip the offending mesh
    } else { throw e; }
}

Prevention

When it happens

Trigger: Calling GLTFExporter export functions (e.g. ExportMeshesAsync / ExportSceneAsync) on a mesh whose VertexBuffer was created without CPU-accessible data, whose buffer data was disposed, or whose Buffer.getData() returns null because the data only lives on the GPU (created with updatable=false and filled via GPU, or created from a typed array later discarded after upload).

Common situations: Exporting a scene where meshes were created with new VertexBuffer(engine, ..., updatable=false) and their CPU copies freed; exporting after dispose() was called on geometry; loading meshes via an optimized pipeline that drops CPU buffers; exporting custom meshes whose buffers were set with setDataOnlyOnGPU behavior.

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/72d6b41e0f01c47c. Report an issue: GitHub.