Dynamic BufferGeometry disappears when re-setting the position buffer attribute

I create a BufferGeometry and set its attributes like so:

        this.addGroup(groupStart, groupCount, 0);
        const indexAttribute = new BufferAttribute(new Uint32Array(indices), 1);
        const positionAttribute = new BufferAttribute(new Float32Array(verticesCount * 3), 3);
        this.setAttribute('position', positionAttribute);

Now occasionally I recall this setup code if the number of vertices changes. The strange thing is that the mesh using this BufferGeometry will disappear if the number of vertices INCREASES to be more than the initial number. Even more strangely so, it will still be visible in shadow-maps and only the direct rendering will disappear.

However, if I add

        for (const key of Object.keys(this.attributes)) {

next to the


call, effectively removing all attributes first before setting a new one, it will work properly.
What I suspect is, that the new position-buffer-attribute never gets re-set (that’s why it works when the number of vertices DECREASES (still working on the original buffer), but won’t work when INCREASING them.
Is this intended behaviour ?

It is not intended to overwrite existing attributes with different sizes. Call dispose() on the old geometry and then create a new one.

Ideally, you avoid all of this and create a geometry with sufficiently large buffers right from the beginning. If you don’t need all of its space, use setDrawRange() to define what parts of the buffer should be rendered.

Okay. Do you see a problem with the workaround of removing the attributes before re-setting them as stated in the workaround ?
This way I could handle everything inside the custom geometry class and the user of that class doesn’t need to worry about recreating it under certain conditions.

I don’t recommend doing changing a geometry configuration after the initial render. Ideally, you set attribute once. This will be the most performant solution.