Search Unity

[WebAssembly] Error on loading "TypeError: undefined is not an object"

Discussion in 'Web' started by DiegoR, Jul 25, 2019.

  1. DiegoR

    DiegoR

    Joined:
    Oct 31, 2012
    Posts:
    33
    If I build the game with Unity 2018.4 or Unity 2019.1: The following error appears in the middle of the loading of the game:

    TypeError: undefined is not an object (evaluating 'Module["asm"]["stackSave"].apply')

    The error line is the following line:
    Code (javascript):
    1.  
    2. var stackSave = Module["stackSave"] = (function() {
    3.             return Module["asm"]["stackSave"].apply(null, arguments)
    4.         });
    5.  
    The code is not part of the logic of the game itself. It's seems to be part of the glue code generated by Unity (generated from the file "...wasm.framework.unityweb")

    I can close the popup and the game will finish its loading and runs perfectly.

    Tried with Chrome and Safari (both of them updated to their latest versions). Same results.

    The error do _not_ appear if I build the game with "Development build" marked.
    The error do _not_ appear if I build the game using Unity 2018.4 but selecting "asm.js" as Linker Target. So I guess it's related to the WebAssembly generated code but I didn't find a workaround to avoid it.

    I cannot select "asm.js" on Unity 2019.1 because it was deprecated.

    For the moment, I can stick to Unity 2018.4 and "asm.js" but the truth is that the game runs smoother with WebAssembly, the size of all the package is 5 Mb less and eventually I will need to leave "asm.js" because I will requiere to use latest version of Unity.
     
    Last edited: Jul 25, 2019
  2. DiegoR

    DiegoR

    Joined:
    Oct 31, 2012
    Posts:
    33
    I found a workaround:

    Wait for the exception on the browser appear. Click the link where the error line is described, it will open the disassembled javascript code of the file "game.wasm.framework.unityweb" and add the null check before access the functions of the object.

    For example, change this code:

    Code (javascript):
    1.  
    2.         var stackSave = Module["stackSave"] = (function() {
    3.             return Module["asm"]["stackSave"].apply(null, arguments)
    4.         });
    5.  
    for this one:

    Code (javascript):
    1.  
    2.         var stackSave = Module["stackSave"] = (function() {
    3.             if (Module["asm"]["stackSave"] != null)
    4.                 return Module["asm"]["stackSave"].apply(null, arguments)
    5.             else
    6.                 return null;
    7.         });
    8.  
    My hypothesis regarding the problem is related to a race condition in the loading time when the module references array is being made. Sometimes the game starts before the module references array is completed and some objects are still null.

    I will keep trying to find a final solution to this problem.
     
  3. doctorpangloss

    doctorpangloss

    Joined:
    Feb 20, 2013
    Posts:
    270
    Code stripping is probably responsible, and this error is just really esoteric.

    Try building for other IL2CPP platforms with 2019 and see if it works.

    Also, do you build from the command line? There are some subtle issues I've experienced building from the command line.