WebGPU: Geometry._invalidateVertexBuffers throws 'mesh.subMeshes is not iterable' for a mesh without sub-meshes

Open Beginner friendly
#19,188 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@vladosskins178 is already working on this.

Since Nov 18, 2026.

  • #19189 by @vladosskins178 — open

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
frontend

Research direction

Search the dev/core Meshes sources for _invalidateVertexBuffers on Geometry (the loop introduced in #19051) and compare it with how AbstractMesh guards subMeshes elsewhere. Add the missing guard there, then run the reproduction: VertexData.applyToMesh with empty positions/normals/indices on a fresh mesh under the WebGPU engine, plus the geometry unit tests. Done means the snippet no longer throws and the second case (makeGeometryUnique on a cloned asset container mesh) also passes.

Written by the indexing model from the issue text.

Description

Version: 9.37.1 (present since 9.33.3; 9.32.0 is not affected). WebGPU engine only.

What happens

Since #19051, Geometry._invalidateVertexBuffers() walks every mesh of the geometry and its subMeshes:

for (const mesh of this._meshes) {
    for (const subMesh of mesh.subMeshes) {
        subMesh._invalidateVertexBuffers();
    }
}

mesh.subMeshes is undefined until the mesh has been given sub-meshes (AbstractMesh guards for this elsewhere with if (!this.subMeshes)), so setting a vertex buffer on such a mesh throws:

TypeError: mesh.subMeshes is not iterable
    at Geometry._invalidateVertexBuffers
    at Geometry.setVerticesBuffer
    at Geometry.setVerticesData
    at Mesh.setVerticesData
    at VertexData._applyToCoroutine

Two ways we hit it

  1. Applying empty vertex data to a new mesh. The first buffer (positions, empty) creates the geometry without a global sub-mesh; the second buffer (normals) throws:
const mesh = new BABYLON.Mesh("empty", scene);
const data = new BABYLON.VertexData();
data.positions = [];
data.normals = [];
data.indices = [];
data.applyToMesh(mesh); // throws on WebGPU; on 9.32.0 it only warned about the empty array
  1. mesh.makeGeometryUnique() on meshes cloned from a glTF AssetContainer with instantiateModelsToScene(name => name, false, { doNotInstantiate: true }): it threw for a mesh in the hierarchy, in the same function.

(The snippet is reduced from an application, not yet run in the Playground.)

Expected

No exception: a mesh without sub-meshes has no cached draws to invalidate.

Suggested fix

Skip meshes that have none:

for (const mesh of this._meshes) {
    if (!mesh.subMeshes) {
        continue;
    }
    for (const subMesh of mesh.subMeshes) {
        subMesh._invalidateVertexBuffers();
    }
}

We run with exactly that as a patch over Geometry.prototype._invalidateVertexBuffers and both cases work.

Dominant language
TypeScript
Stars
26.6k
Forks
3.8k
Avg merge
1d 9h
Merged PRs (30d)
112

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from BabylonJS/Babylon.js

All issues in BabylonJS/Babylon.js

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.