WebAssembly error: index out of bounds

Receiving this error in Unity 5.6.0f3 with a WebAssembly build:

exception thrown: RuntimeError: index out of bounds,wasm-function[944]

This happens after onRuntimeInitialized is called on the WebGL module but before the first debug is printed from the game client itself.

Build Settings: Data caching is ON, and Enable Exceptions are Explicitly thrown.

Any thoughts?

Thanks.

Which browser? Could you try a different one? (perhaps you get a better error)
Any problem in asm.js (wasm disabled)?

Marco,

The error above is from FireFox 53. I get this in Chrome 57.0.2987.133:

exception thrown: RuntimeError: memory access out of bounds,RuntimeError: memory access out of bounds
at ([944]+28)
at ([42281]+249)
at ([42201]+458)
at ([42196]+45)
at ([42195]+1)
at ([30326]+67)
at ([30321]+148)
at Object.UnityLoader.69624c7248aa625792505cdcc3bef985.Module._main (blob:…)
at Object.callMain

When built without WebAssembly, the build runs fine.

BTW, is there a way to disable WebAssembly even after it is built? Just removing the WASM URLs from the JSON file?

Thanks.

add

UnityLoader.SystemInfo.hasWasm = false;

to the generated html, right before calling UnityLoader.instantiate()

What’s the value of WebGLMemorySize?
is TOTAL_MEMORY in the json file consistent with that value?

WebGLMemorySize is set to 400. TOTAL_MEMORY in the json file = 419430400

So I may have figured out the issue.

Somehow the Standard Shader got included in the build (via Graphics Settings->Always Include Shaders) which blew up the data file size to >20MB. When this is removed, the data file size is significantly smaller (1.6MB in our case) and the build seems to run fine (so far)…

Welp, that didn’t last long:

UnityLoader.js?_=1493989526999:1 Invoking error handler due to
Script error.
wasm-03b8803e-27828:7 Uncaught RuntimeError: memory access out of bounds
at ([27828]+12)
at ([27826]+145)
at ([30239]+25)
at UnityLoader.47c5673658101c1a5e0e999eb44b3e52.Module._SendMessage

So it seems to happen on some SendMessage calls from javascript into Unity.

@sirrus how did you solved the issue?

To be honest, I don’t quite recall. It may have been that we were trying to override the TOTAL_MEMORY value in the Unity loader module which isn’t allowed in WebAssembly (which is what I think Marco was getting at).

Hi @Marco-Trivellato , @sirrus , @Gaurav-Gulati

I’m also facing my problem when build and run Unity WebGL on 2 browsers and get difference results:
— Firefox: index out of bounds.
— Chrome: memory access out of bounds.
WebGLMemorySize: default 256.

Can you help me resolve my problem?
Thank you so much :slight_smile:

Commented in the other thread webgl failed to build my project - Unity Engine - Unity Discussions . When you see an error like index out of bounds, try doing a Development build and get the callstack of where the error occurs from there. That can give a clue as to whether it is a Unity bug or a browser bug, or something else.

1 Like

Oh I see that => that problem is websocket.
Thank you so much.

Hi @jukka_j
Can I open WebGL in mobile devices?

Unity WebGL exports are not currently tailored for mobile use, but nothing is really stopping you from doing so. If you edit the UnityLoader.js script inside Unity installation tree, you can remove the mobile WebGL unsupported notification dialog. Check out other threads in this forum for tips and recommendations on how to optimize for mobile use.