BabylonJS/Babylon.js · error · Error
Draco: Cannot decode invalid geometry type ${type}
Error message
Draco: Cannot decode invalid geometry type ${type} What it means
DecodeMesh switches on decoder.GetEncodedGeometryType(buffer) and only handles TRIANGULAR_MESH and POINT_CLOUD. Any other (or unknown) geometry type falls into the default branch and throws this Error, because Babylon has no decoding path for it.
Source
Thrown at packages/dev/core/src/Meshes/Compression/dracoCompressionWorker.ts:236
} finally {
decoderModule._free(ptr);
}
geometry = mesh;
break;
}
case decoderModule.POINT_CLOUD: {
const pointCloud = new decoderModule.PointCloud();
status = decoder.DecodeBufferToPointCloud(buffer, pointCloud);
if (!status.ok() || !pointCloud.ptr) {
throw new Error(status.error_msg());
}
geometry = pointCloud;
break;
}
default: {
throw new Error(`Draco: Cannot decode invalid geometry type ${type}`);
}
}
const numPoints = geometry.num_points();
const processAttribute = (decoder: Decoder, geometry: Mesh | PointCloud, kind: string, attribute: any /** Attribute */) => {
const dataType = attribute.data_type();
const numComponents = attribute.num_components();
const normalized = attribute.normalized();
const byteStride = attribute.byte_stride();
const byteOffset = attribute.byte_offset();
const dataTypeInfo: Record<number, { typedArrayConstructor: TypedArrayConstructor; heap: TypedArray }> = {
[decoderModule.DT_FLOAT32]: { typedArrayConstructor: Float32Array, heap: decoderModule.HEAPF32 },
[decoderModule.DT_INT8]: { typedArrayConstructor: Int8Array, heap: decoderModule.HEAP8 },
[decoderModule.DT_INT16]: { typedArrayConstructor: Int16Array, heap: decoderModule.HEAP16 },
[decoderModule.DT_INT32]: { typedArrayConstructor: Int32Array, heap: decoderModule.HEAP32 },
[decoderModule.DT_UINT8]: { typedArrayConstructor: Uint8Array, heap: decoderModule.HEAPU8 },
View on GitHub (pinned to 0592b347b8)
Solutions
- Validate the input is genuine Draco data before decoding (magic bytes / known source).
- Re-export the asset ensuring it is encoded as a mesh or point cloud.
- Check for buffer truncation that corrupts the geometry type field.
- If the type is valid but unsupported by Babylon, decode it with the raw Draco module directly instead.
Example fix
// before
const geo = await DecodeMesh(buffer); // buffer is not Draco -> type = -1
// after
function isLikelyDraco(buf: ArrayBuffer) { return buf.byteLength > 5; } // plus real validation
if (isLikelyDraco(buffer)) {
const geo = await DecodeMesh(buffer);
} Defensive patterns
Strategy: try-catch
Validate before calling
// decode and inspect geometry type before relying on Babylon's worker
type === decoderModule.TRIANGULAR_MESH || type === decoderModule.POINT_CLOUD
? proceed : reject('unsupported Draco geometry type: ' + type); Type guard
const isSupportedGeometryType = (type: number): type is 0 | 1 => type === 0 /* TRIANGULAR_MESH */ || type === 1 /* POINT_CLOUD */;
Try / catch
try {
geometry = await DecodeMesh(buffer);
} catch (e) {
if (String(e?.message).includes('invalid geometry type')) {
throw new Error('Asset is not a decodable Draco mesh/point cloud; check source data');
}
throw e;
} Prevention
- Only feed the decoder buffers from trusted Draco sources.
- Check for truncation/corruption before decoding (headers include the type).
- Fail fast in CI by decoding every compressed asset once at build time.
- Pin decoder module versions to avoid unknown new geometry types.
When it happens
Trigger: Decoding a Draco buffer whose encoded geometry type is neither TRIANGULAR_MESH nor POINT_CLOUD (e.g. invalid/corrupted data causing GetEncodedGeometryType to return an unexpected value, or a future/unknown Draco geometry type).
Common situations: Corrupted headers making the type byte garbage; decoding arbitrary binary data that merely resembles Draco; using a decoder that returns -1/INVALID for failed type detection.
Related errors
- The provided data is not a valid KTX2 file.
- Failed to decode the KTX2 file: expected ${layerCount} layer
- Draco: Missing position attribute for encoding.
- status.error_msg()
- Draco: Cannot decode invalid data type ${dataType}
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/5ed7aa5e0993687f.
Report an issue: GitHub.