# Fix BufferGeometry

**URL:** <https://discourse.threejs.org/t/fix-buffergeometry/66819>\
**Category:** Questions\
**Tags:** buffergeometry, geometry\
**Created:** [June 13, 2024, 10:48am UTC](https://discourse.threejs.org/t/fix-buffergeometry/66819 "2024-06-13T10:48:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lock\_Basta](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/lock_basta/32/48231_2.png) [@Lock\_Basta](https://discourse.threejs.org/u/Lock_Basta)\
**Post date:** [June 13, 2024, 10:48am UTC](https://discourse.threejs.org/t/fix-buffergeometry/66819/1 "2024-06-13T10:48:33Z")

</div>

Hi all, I’m trying to create a WallGeometry (like in Cesium; I have a pet project called Cesium + Three), but I have my geometry crashing when updating for some reason. What is the problem? I do everything in this class:

```javascript
export class WallGeometry extends BufferGeometry {
    constructor(vertices) {
        super();

        if (vertices.length % 6 !== 0) {
            throw new Error('Vertices array length must be a multiple of 6');
        }

        const positions = [];
        const indices = [];
        const baseVerticesCount = vertices.length / 6;

        for (let i = 0; i < baseVerticesCount; i++) {
            const bottomX = vertices[i * 6];
            const bottomY = vertices[i * 6 + 1];
            const bottomZ = vertices[i * 6 + 2];
            const topX = vertices[i * 6 + 3];
            const topY = vertices[i * 6 + 4];
            const topZ = vertices[i * 6 + 5];

            positions.push(bottomX, bottomY, bottomZ);
            positions.push(topX, topY, topZ);
        }

        for (let i = 0; i < baseVerticesCount - 1; i++) {
            const bottomLeft = i * 2;
            const topLeft = bottomLeft + 1;
            const bottomRight = bottomLeft + 2;
            const topRight = bottomRight + 1;

            indices.push(bottomLeft, topLeft, bottomRight);
            indices.push(topLeft, topRight, bottomRight);
        }

        const bottomLeft = (baseVerticesCount - 1) * 2;
        const topLeft = bottomLeft + 1;
        const bottomRight = 0;
        const topRight = 1;

        indices.push(bottomLeft, topLeft, bottomRight);
        indices.push(topLeft, topRight, bottomRight);
        this.setIndex(indices);
        this.setAttribute('position', new Float32BufferAttribute(positions, 3));
        this.computeVertexNormals();

        
    }

    updateGeometry(newPoints) {
        const newVertices = [];
        console.log(newPoints, 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAA')
        for (let i = 0; i < newPoints.length; i += 2) {
            const upper = newPoints[i];
            const lower = newPoints[i + 1];

            newVertices.push(upper.L, upper.B, upper.H);
            newVertices.push(lower.L, lower.B, 0);
        }

        const newCartesianVertices = fromDegreesToCartesian3(newVertices);

        const positionAttribute = this.getAttribute('position');
        const currentVertices = positionAttribute.array;
        const indexAttribute = this.getIndex();
        const currentIndices = indexAttribute.array;

        const combinedVertices = new Float32Array(currentVertices.length + newPoints.length);
        combinedVertices.set(currentVertices);
        combinedVertices.set(newPoints, currentVertices.length);

        const baseIndex = currentVertices.length / 3;
        const newIndices = [];
        const baseVerticesCount = newPoints.length / 3 / 2;
        for (let i = 0; i < baseVerticesCount - 1; i++) {
            const bottomLeft = baseIndex + i * 2;
            const topLeft = bottomLeft + 1;
            const bottomRight = bottomLeft + 2;
            const topRight = bottomRight + 1;

            newIndices.push(bottomLeft, topLeft, bottomRight);
            newIndices.push(topLeft, topRight, bottomRight);
        }

        const bottomLeft = baseIndex + (baseVerticesCount - 1) * 2;
        const topLeft = bottomLeft + 1;
        const bottomRight = baseIndex;
        const topRight = bottomRight + 1;

        newIndices.push(bottomLeft, topLeft, bottomRight);
        newIndices.push(topLeft, topRight, bottomRight);

        const combinedIndices = new Uint16Array(currentIndices.length + newIndices.length);
        combinedIndices.set(currentIndices);
        combinedIndices.set(newIndices, currentIndices.length);

        this.setAttribute('position', new Float32BufferAttribute(combinedVertices, 3));
        this.setIndex(new Uint16BufferAttribute(combinedIndices, 1));

        this.attributes.position.needsUpdate = true;
        this.index.needsUpdate = true;
        this.computeVertexNormals();
        this.needsUpdate = true;
    }
}

```

vertices and newPoints format data: [L,B,H,L,B,0]. They have already been converted with Cartesian3.fromDegrees.

 ![Wall](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/6/5/652444b667ae8b8ea44c18e60008c9b1f1717b9f.png)

---

<div class="post-metadata">

**Author:** ![Arthur](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/arthur/32/22954_2.png) [@Arthur](https://discourse.threejs.org/u/Arthur)\
**Post date:** [June 13, 2024, 12:24pm UTC](https://discourse.threejs.org/t/fix-buffergeometry/66819/2 "2024-06-13T12:24:51Z")

</div>

Are you getting an error in the console? What do you mean by ‘crashing when updating’?
