[WebGPU] A cached `ComputeEffect` ignores later callers' `onError` and keeps the first caller's callbacks forever
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 58/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- computer-graphics, performance
Research direction
Start in Engines/WebGPU/Extensions/engine.computeShader.pure.js at the cache-hit branch of createComputeEffect (around lines 170-182), then read the onCompiled/onError hand-off in Compute/computeShader.pure.js (around lines 260-265). Run the repro with two ComputeShaders using the same invalid source. Done means the second shader's onError fires, and the cached effect no longer holds the first caller's callbacks.
Written by the indexing model from the issue text.
Description
Summary
WebGPUEngine.createComputeEffect returns an existing ComputeEffect when the key (source + defines) matches. On that cache hit it:
- ignores the new caller's
onError, and callsonCompiledonly if the effect is already ready; - leaves the cached effect holding the first caller's
onCompiledandonError.
So:
- A second
ComputeShaderwith the same source never hears about a compilation error. ItsonErroris silently dropped. - Whatever the first caller's callbacks capture stays reachable for the engine's lifetime.
ComputeShaderhas nodispose(), and nothing ever removes entries from_compiledComputeEffectsexceptreleaseComputeEffects().
Where
Engines/WebGPU/Extensions/engine.computeShader.pure.js:170-182, increateComputeEffect:if (this._compiledComputeEffects[name]) { const compiledEffect = this._compiledComputeEffects[name]; if (options.onCompiled && compiledEffect.isReady()) { options.onCompiled(compiledEffect); } return compiledEffect; // options.onError is ignored; the first caller's callbacks stay on the effect }Compute/computeShader.pure.js:260-265:ComputeShaderpassesonCompiled: this.onCompiled, onError: this.onErrorstraight intocreateComputeEffect.
Repro (Playground, WebGPU: https://playground.babylonjs.com/?webgpu#GK5KU8#1)
const source = "@compute @workgroup_size(1) fn main() { let x : f32 = notDefinedAnywhere; }"; // invalid on purpose
const calls = [];
const make = (label) => {
const cs = new BABYLON.ComputeShader(label, engine, { computeSource: source }, { bindingsMapping: {} });
cs.onError = () => calls.push(label);
return cs;
};
const first = make("first"); first.isReady();
// ...wait for the compile result...
const second = make("second"); second.isReady();
// expected: calls = ["first", "second"]
// actual: calls = ["first"]; second._effect === first._effect, and that effect's onError === first.onError
Measured in my game
Our foliage culling used shader.onError = (effect, error) => { this.failure = error; }. Through the cached effect's onError closure, that kept the first stage's batch object, and with it that stage's whole Scene, alive for the session. Heap-snapshot retainer path: WebGPUEngine._compiledComputeEffects[...] → ComputeEffect.onError → closure context → ComputeFoliageBatch.scene → Scene.
Suggested fix
- On a cache hit, attach the caller's callbacks for that caller only. For example, register them on
onCompileObservableandonErrorObservable(callonErrorimmediately if the effect already failed) instead of relying on the first caller's options. - Don't keep per-caller callbacks on the shared cached effect.
- Optionally give
ComputeShaderadispose()that removes its observers.
Workaround we use
Build onError handlers at module scope so the closure captures only a WeakRef to its owner. Read the compile error from the effect when needed rather than relying on a per-shader onError.
Related
No issue, PR or forum thread found. PR #18955 "Add on error on EffectWrapper" (merged 2026-09-30) is adjacent, adding onError for EffectWrapper rather than compute effects.
- 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: Geometry._invalidateVertexBuffers throws 'mesh.subMeshes is not iterable' for a mesh without sub-meshesPossibly taken @vladosskins178 claimed this 14 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
BabylonJS/Babylon.js#19188 ·
Maintainers usually reply within 1 day
-
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
-
in 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
All issues in BabylonJS/Babylon.js
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
ardia-browser/ardia#6391 ·
Maintainers usually reply within 1 day
-
Feature:Actions/ConnectorTypes Team:ResponseOps
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
elastic/kibana#309028 · 1 comment ·
Maintainers usually reply within 1 day
-
🔨 tool 🧰 library
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Orange-OpenSource/Orange-Boosted-Bootstrap#4035 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
DISIC/teleservice-conformite#230 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
rothgar/rabble.radio#410 ·
Maintainers usually reply within 1 day