{"record":{"id":"277c75c729802d39","repo":"BabylonJS/Babylon.js","slug":"csg-must-be-used-with-geometries-having-the-same-n","errorCode":null,"errorMessage":"CSG must be used with geometries having the same number of properties","messagePattern":"CSG must be used with geometries having the same number of properties","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Meshes/csg2.ts","lineNumber":126,"sourceCode":"    private _numProp: number;\r\n    private _vertexStructure: IManifoldVertexComponent[];\r\n\r\n    /**\r\n     * Return the size of a vertex (at least 3 for the position)\r\n     */\r\n    public get numProp() {\r\n        return this._numProp;\r\n    }\r\n\r\n    private constructor(manifold: any, numProp: number, vertexStructure: IManifoldVertexComponent[]) {\r\n        this._manifold = manifold;\r\n        this._numProp = numProp;\r\n        this._vertexStructure = vertexStructure;\r\n    }\r\n\r\n    private _process(operation: \"difference\" | \"intersection\" | \"union\", csg: CSG2) {\r\n        if (this.numProp !== csg.numProp) {\r\n            throw new Error(\"CSG must be used with geometries having the same number of properties\");\r\n        }\r\n        return new CSG2(Manifold[operation](this._manifold, csg._manifold), this.numProp, this._vertexStructure);\r\n    }\r\n\r\n    /**\r\n     * Run a difference operation between two CSG\r\n     * @param csg defines the CSG to use to create the difference\r\n     * @returns a new csg\r\n     */\r\n    public subtract(csg: CSG2) {\r\n        return this._process(\"difference\", csg);\r\n    }\r\n\r\n    /**\r\n     * Run an intersection operation between two CSG\r\n     * @param csg defines the CSG to use to create the intersection\r\n     * @returns a new csg\r\n     */\r","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Meshes/csg2.ts#L108-L144","documentation":"CSG2 operations (add/subtract/intersect via _process) require both operands to use the same vertex property count (numProp) so Manifold can combine the vertex structures. Mixing geometries with different attribute layouts (e.g. one with UVs/normals and one without) makes the result undefined, so the library throws.","triggerScenarios":"Calling csgA.subtract(csgB), .add() or .intersect() where the two CSG2 objects were built from meshes with different vertex structures (different number of position/normal/uv/color attributes).","commonSituations":"Subtracting a primitive (no UVs) from a loaded mesh (with UVs); combining meshes from different importers; enabling/disabling attribute computation inconsistently when creating the CSGs.","solutions":["Build both CSG2 objects from meshes with identical vertex attribute layouts (same enablement of normals/UVs/colors)","Recreate one CSG via CSG2.FromMesh with matching options so numProp aligns","Check csgA.numProp === csgB.numProp before performing the operation"],"exampleFix":"// before\nconst a = CSG2.FromMesh(meshWithUVs);\nconst b = CSG2.FromMesh(plainBox); // different numProp\na.subtract(b);\n// after\nconst b = CSG2.FromMesh(plainBox, scene, undefined, { sameAttributeOptionsAsMeshWithUVs });\na.subtract(b); // matching numProp","handlingStrategy":"validation","validationCode":"if (a.numProp !== b.numProp) {\n  throw new Error(`CSG numProp mismatch: ${a.numProp} vs ${b.numProp}; rebuild one operand with matching attributes`);\n}","typeGuard":"const compatible = (a: CSG2, b: CSG2): boolean => a.numProp === b.numProp;","tryCatchPattern":"try {\n  return a.subtract(b);\n} catch (e) {\n  if (String(e).includes('same number of properties')) {\n    return a.subtract(CSG2.FromMesh(sourceMeshB, scene, undefined, matchingOptions));\n  }\n  throw e;\n}","preventionTips":["Create all CSG operands with identical attribute options (normals/UVs/colors)","Assert numProp equality in your mesh-processing pipeline","Avoid mixing primitives and imported meshes without normalizing attributes"],"tags":["csg","geometry","validation"],"backgroundTag":"geometry-schema-mismatch","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}