WebGPU: Geometry._invalidateVertexBuffers throws 'mesh.subMeshes is not iterable' for a mesh without sub-meshes
Maintainers usually reply within 1 day
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
- 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
mesh.makeGeometryUnique()on meshes cloned from a glTFAssetContainerwithinstantiateModelsToScene(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
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from BabylonJS/Babylon.js
-
WebGPU compressed cube readback feeds encoded blocks to diffuse irradiance calculationPossibly taken @yucheng-du claimed this 1 day ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 54/100
BabylonJS/Babylon.js#19278 ·
Maintainers usually reply within 1 day
-
[WebGPU] A render effect whose WGSL fails to compile never reaches onError: isReady() is true and every draw fails on an invalid pipelinePossibly taken @Popov72 claimed this today. Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
BabylonJS/Babylon.js#19224 · 2 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
Atmosphere: floating origin mode assumes the world origin is the planet centre (black sky in ground-level scenes)Possibly taken A pull request linked to this issue is open or already merged. Openin progress
Difficulty 4/5 3-5 days Newbie friendliness 48/100
BabylonJS/Babylon.js#19212 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
-
enhancement Gaussian Splatting native
Difficulty 4/5 3-5 days Newbie friendliness 43/100
BabylonJS/Babylon.js#19145 · 1 assignee ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 58/100
BabylonJS/Babylon.js#19131 ·
Maintainers usually reply within 1 day
All issues in BabylonJS/Babylon.js
Similar issues
-
Add: Alfa DramasOpencheck:passed streams:add
Difficulty 1/5 Under an hour Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
moq-dev/moq#10463 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
ardia-browser/ardia#6391 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
liberation-data/desk#68 ·
Maintainers usually reply within 1 day
-
usability
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
inmanta/web-console#8165 ·
Maintainers usually reply within 1 day