# Webgpu Cannot allocate Wasm memory for new instance

**URL:** <https://forum.babylonjs.com/t/webgpu-cannot-allocate-wasm-memory-for-new-instance/48321>\
**Category:** Questions\
**Tags:** documentation\
**Created:** [February 27, 2024, 6:33am UTC](https://forum.babylonjs.com/t/webgpu-cannot-allocate-wasm-memory-for-new-instance/48321 "2024-02-27T06:33:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rookiewxy](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rookiewxy/32/35612_2.png) [@rookiewxy](https://forum.babylonjs.com/u/rookiewxy)\
**Post date:** [February 27, 2024, 6:33am UTC](https://forum.babylonjs.com/t/webgpu-cannot-allocate-wasm-memory-for-new-instance/48321/1 "2024-02-27T06:33:31Z")

</div>

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 {  
console.warn(  
“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”);  
}  
}

---

<div class="post-metadata">

**Author:** ![rookiewxy](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rookiewxy/32/35612_2.png) [@rookiewxy](https://forum.babylonjs.com/u/rookiewxy)\
**Post date:** [February 27, 2024, 6:36am UTC](https://forum.babylonjs.com/t/webgpu-cannot-allocate-wasm-memory-for-new-instance/48321/2 "2024-02-27T06:36:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [February 27, 2024, 12:09pm UTC](https://forum.babylonjs.com/t/webgpu-cannot-allocate-wasm-memory-for-new-instance/48321/3 "2024-02-27T12:09:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rookiewxy](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rookiewxy/32/35612_2.png) [@rookiewxy](https://forum.babylonjs.com/u/rookiewxy)\
**Post date:** [February 28, 2024, 1:28am UTC](https://forum.babylonjs.com/t/webgpu-cannot-allocate-wasm-memory-for-new-instance/48321/4 "2024-02-28T01:28:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [February 28, 2024, 9:48am UTC](https://forum.babylonjs.com/t/webgpu-cannot-allocate-wasm-memory-for-new-instance/48321/5 "2024-02-28T09:48:06Z")

</div>

> [@rookiewxy](#):
>
> maybe I have a shader to write dynamic sky box is more memory consuming?

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:

```javascript
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…

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [February 28, 2024, 10:29am UTC](https://forum.babylonjs.com/t/webgpu-cannot-allocate-wasm-memory-for-new-instance/48321/6 "2024-02-28T10:29:40Z")

</div>

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

> <https://github.com/BabylonJS/Babylon.js/pull/14815>
>
> See https://forum.babylonjs.com/t/webgpu-cannot-allocate-wasm-memory-for-new-ins…tance/48321/5

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