Webgpu Cannot allocate Wasm memory for new instance

Use webgpu for initialization, but after rendering the scene a few more times it will display :8888/#/screen/17540… 2af33e895048f7e88:1 Uncaught (in promise) RangeError: WebAssembly.instantiate(): Out of memory: Cannot allocate Wasm memory for new instance error, so I want to make a bottom line scheme, after capturing this error, use webgl mode to render, but I can not capture, the code is as follows

async createEngine(dom: HTMLCanvasElement) {
if (dom) {
try {
const webgpuSupported = await BABYLON.WebGPUEngine.IsSupportedAsync;
if (webgpuSupported) {
this.engine = await new BABYLON.WebGPUEngine(dom);
await (this.engine as BABYLON.WebGPUEngine).initAsync();
} else {
“WebGPU is not supported. Falling back to standard Babylon.js engine.”
this.engine = new BABYLON.Engine(dom, true);
} catch (error) {
throw new Error(error as string);
return this.engine;
} else {
throw new Error(“dom element missing”);

Does initAsync return a message about whether the creation was correct or not, which is to use webgl to load, but now returns void regardless of whether it was successful or not, how should I capture the corresponding creation result, or is there an attribute for me to make a judgment

I never got this error message…

Are you sure you’re not recreating the WebGPU engine multiple times?

Regarding the error, I would have thought that a try/catch would have worked…

If you can set up a reproduction, it will be easier to help you.

Do not repeat the creation many times, maybe I have a shader to write dynamic sky box is more memory consuming? I thought so. try… catch… It will work, but it won’t catch initAsync errors, so I would say does the engine instance have any indication that it failed to create

This is using GPU memory, not WASM (CPU) memory, so it should not be a problem.

initAsync returns a promise, so you can try something like this:

engine.initAsync().then(() => {
  // everything ok
}).catch((err) => {
  // an error occurred

But it’s normally the same thing than awaiting on initAsync() and using a try/catch to handle the error…

The error handling during WebGPU creation/initialization could be simplified a bit, though, so here’s a PR for this:

You may test if a try/catch works better when these changes are merged.

1 Like