{"record":{"id":"b90726040c54609c","repo":"BabylonJS/Babylon.js","slug":"draco-cannot-encode-geometry-with-no-vertices","errorCode":null,"errorMessage":"Draco: Cannot encode geometry with no vertices.","messagePattern":"Draco: Cannot encode geometry with no vertices\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Meshes/Compression/dracoEncoder.ts","lineNumber":272,"sourceCode":"\r\n        if (this._modulePromise) {\r\n            const encoder = await this._modulePromise;\r\n            return EncodeMesh(encoder.module, attributes, indices, mergedOptions);\r\n        }\r\n\r\n        throw new Error(\"Draco: Encoder module is not available\");\r\n    }\r\n\r\n    /**\r\n     * Encodes a mesh or geometry into a Draco-encoded mesh data.\r\n     * @param input the mesh or geometry to encode\r\n     * @param options options for the encoding\r\n     * @returns a promise that resolves to the newly-encoded data\r\n     */\r\n    public async encodeMeshAsync(input: Mesh | Geometry, options?: IDracoEncoderOptions): Promise<IDracoEncodedMeshData> {\r\n        const verticesCount = input.getTotalVertices();\r\n        if (verticesCount == 0) {\r\n            throw new Error(\"Draco: Cannot encode geometry with no vertices.\");\r\n        }\r\n\r\n        // Prepare parameters for encoding\r\n        if (input instanceof Mesh && input.morphTargetManager && options?.method === \"MESH_EDGEBREAKER_ENCODING\") {\r\n            Logger.Warn(\"Draco: Cannot use EDGEBREAKER encoding method with morph targets. Falling back to SEQUENTIAL method.\");\r\n            options.method = \"MESH_SEQUENTIAL_ENCODING\";\r\n        }\r\n\r\n        const indices = PrepareIndicesForDraco(input);\r\n        const attributes = PrepareAttributesForDraco(input, options?.excludedAttributes);\r\n\r\n        return await this._encodeAsync(attributes, indices, options);\r\n    }\r\n}\r\n","sourceCodeStart":254,"sourceCodeEnd":287,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Meshes/Compression/dracoEncoder.ts#L254-L287","documentation":"DracoEncoder.encodeMeshAsync throws when `input.getTotalVertices()` is 0 — Draco encodes vertex data, and a mesh/geometry with no vertices cannot be encoded. The check happens before any attribute preparation.","triggerScenarios":"Calling `encodeMeshAsync` on an empty Mesh (never given geometry), a disposed mesh, a Geometry with no vertex buffer, or a mesh whose vertex data was released (e.g. after `mesh.geometry.releaseVertexArray...` or `freeze`+free memory patterns).","commonSituations":"Batch-encoding many meshes where some are empty placeholders; encoding a mesh before `CreateMesh`/vertex data assignment; procedural meshes that failed to build; assets where all meshes LOD0 is empty.","solutions":["Check `mesh.getTotalVertices() > 0` before encoding and skip empty meshes.","Ensure the mesh actually has geometry assigned before encoding (create/attach vertex data first).","For batch pipelines, filter the list: `meshes.filter(m => m.getTotalVertices() > 0)`.","If geometry was released, re-load or re-assign the vertex data before encoding."],"exampleFix":"// before\nfor (const mesh of meshes) {\n    await encoder.encodeMeshAsync(mesh);\n}\n\n// after\nfor (const mesh of meshes) {\n    if (mesh.getTotalVertices() === 0) continue;\n    await encoder.encodeMeshAsync(mesh);\n}","handlingStrategy":"validation","validationCode":"if (input.getTotalVertices() === 0) {\n    return null; // skip empty meshes\n}\nreturn await encoder.encodeMeshAsync(input, options);","typeGuard":"function isEncodableDracoInput(input: Mesh | Geometry): boolean {\n    return input.getTotalVertices() > 0;\n}","tryCatchPattern":"try {\n    return await encoder.encodeMeshAsync(mesh);\n} catch (e) {\n    if (e instanceof Error && e.message.includes(\"no vertices\")) {\n        Logger.Warn(`Skipping empty mesh ${mesh.name}`);\n        return null;\n    }\n    throw e;\n}","preventionTips":["Filter meshes with getTotalVertices() === 0 out of encode batches","Encode only after geometry assignment/asset load completes","Watch for disposed or vertex-data-released meshes in pipelines","Log skipped meshes so silent data loss is visible"],"tags":["draco","encoder","validation","empty-geometry"],"backgroundTag":"empty-geometry","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}