Search Unity

WebAssembly error: index out of bounds

Discussion in 'Web' started by sirrus, May 3, 2017.

  1. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
    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.
     
  2. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    Which browser? Could you try a different one? (perhaps you get a better error)
    Any problem in asm.js (wasm disabled)?
     
  3. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
    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 (<WASM>[944]+28)
    at (<WASM>[42281]+249)
    at (<WASM>[42201]+458)
    at (<WASM>[42196]+45)
    at (<WASM>[42195]+1)
    at (<WASM>[30326]+67)
    at (<WASM>[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.
     
  4. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    add
    Code (csharp):
    1. UnityLoader.SystemInfo.hasWasm = false;
    to the generated html, right before calling UnityLoader.instantiate()
     
  5. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    What's the value of WebGLMemorySize?
    is TOTAL_MEMORY in the json file consistent with that value?
     
  6. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
    WebGLMemorySize is set to 400. TOTAL_MEMORY in the json file = 419430400
     
  7. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
    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)...
     
  8. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
    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 (<WASM>[27828]+12)
    at (<WASM>[27826]+145)
    at (<WASM>[30239]+25)
    at UnityLoader.47c5673658101c1a5e0e999eb44b3e52.Module._SendMessage

    So it seems to happen on some SendMessage calls from javascript into Unity.
     
  9. Gaurav-Gulati

    Gaurav-Gulati

    Joined:
    Sep 22, 2014
    Posts:
    52
    @sirrus how did you solved the issue?
     
  10. sirrus

    sirrus

    Joined:
    Jun 10, 2012
    Posts:
    250
    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).
     
  11. nbkhanhdhgd

    nbkhanhdhgd

    Joined:
    Apr 19, 2016
    Posts:
    23
    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 :)
     
  12. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Fearst likes this.
  13. nbkhanhdhgd

    nbkhanhdhgd

    Joined:
    Apr 19, 2016
    Posts:
    23
    Oh I see that => that problem is websocket.
    Thank you so much.
     
  14. nbkhanhdhgd

    nbkhanhdhgd

    Joined:
    Apr 19, 2016
    Posts:
    23
    Hi @jukka_j
    Can I open WebGL in mobile devices?
     
  15. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    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.