WebGPU non-compatibility mode: thinInstanceSetBuffer on a WGSL ShaderMaterial mesh leaves a stale render bundle ("used in submit while destroyed")

With engine.compatibilityMode = false, replacing the thin-instance buffers of a mesh that uses a WGSL ShaderMaterial after it has been drawn leaves its cached render bundle pointing at the old buffer. The old buffer is destroyed, so from then on every submit fails and the canvas stops updating (it goes blank):

WebGPU uncaptured error (1): [object GPUValidationError] - [Buffer "BabylonWebGPUDevice0_DataBufferUniqueId=10_CopyDst_Vertex_Storage_size192"] used in submit while destroyed.
 - While calling [Queue].Submit([[CommandBuffer from CommandEncoder "[60|0] - UploadEncoder"], [CommandBuffer from CommandEncoder "[60|0] - RenderEncoder"]])

Repro (Playground, engine set to WebGPU): Babylon.js Playground

Three thin instances of a box, drawn with a small WGSL ShaderMaterial that reads a per-instance tint attribute. One second in, thinInstanceSetBuffer sets new matrix and tint buffers of the same size: the boxes should move back and turn green. Instead the canvas freezes (blank) and the error above repeats every frame.

  • engine.compatibilityMode = true: works.
  • box.resetDrawCache() right after the thinInstanceSetBuffer calls: works.
  • The same scene with a GLSL ShaderMaterial, or a StandardMaterial with a thin-instance color buffer: works, also in non-compatibility mode.

Reproduced with 9.31.2 and 9.32.0, Chrome 155, Windows 11, NVIDIA RTX 4070 SUPER.

What we think happens. In non-compatibility mode a draw is replayed from WebGPUDrawContext.fastBundle until the draw context or the material context reports a change. setBuffer marks the draw context dirty for the buffers in its bind groups, but nothing does for a new vertex buffer: Geometry.setVerticesBuffer → _notifyUpdate disposes WebGL’s vertex array objects and marks the submeshes’ attributes dirty, and nothing on the WebGPU side drops the bundle. For StandardMaterial (and GLSL ShaderMaterial) the attribute change apparently leads to a new effect or material context, so the bundle is recorded again; for a WGSL ShaderMaterial it doesn’t. The SelectionOutlineLayer bug (thread, fixed in #18238) looks like the same root cause, fixed with mesh.resetDrawCache() inside that layer. A general fix could reset the draw caches of a geometry’s meshes when one of its vertex buffers is replaced (we do that as a workaround, by wrapping Geometry.prototype.setVerticesBuffer), or have the draw context compare vertex-buffer identity the way it does for the bind-group buffers.

In our app it hit a volume pass with a WGSL ShaderMaterial whose thin instances are rebuilt when the camera moves into it: the whole canvas went blank until reload.

Thanks for the clear repro and investigation! I reproduced the issue and opened a fix: BabylonJS/Babylon.js#19051

The fix invalidates cached render bundles when geometry vertex buffers are added, replaced, or removed, without disposing the draw contexts. It uses the existing ownership information—no additional dependency cache or per-frame buffer tracking. In-place buffer updates continue to reuse their bundles.

Until the PR is merged and the fix is available in your version, calling box.resetDrawCache() once after the thinInstanceSetBuffer() calls is the correct workaround. There’s no need to call it every frame.