Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Cannot Enlarge Memory Arrays Browser error

Discussion in 'WebGL' started by nsmith1024, Oct 29, 2018.

  1. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    869
    Hello,

    I created a WebGL app, and ran it in a browser, then i got the error

    Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value 268435456, (2) compile with -s ALLOW_MEMORY_GROWTH=1 which adjusts the size at runtime but prevents some optimizations, (3) set Module.TOTAL_MEMORY to a higher value before the program runs, or if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0

    printErr @ UnityLoader.js:4

    abort @ blob:

    abortOnCannotGrowMemory @ blob:

    enlargeMemory

    Anybody knows how to implement the -s ALLOW_MEMORY_GROWTH=1 or the other options mentioned above to fix this problem.

    im using Unity 2018.1.0

    Thanks
     
  2. kou-yeung

    kou-yeung

    Joined:
    Sep 5, 2016
    Posts:
    30
  3. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    ALLOW_MEMORY_GROWTH=1 is enabled by default when using WebAsssembly. Could you try to switch linker target?
     
    kou-yeung likes this.
  4. l-e-v-a-n

    l-e-v-a-n

    Joined:
    Feb 1, 2020
    Posts:
    8
    can you help me ? same problem
     
  5. squarelover

    squarelover

    Joined:
    Nov 14, 2012
    Posts:
    31
    Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value 268435456, (2) compile with -s ALLOW_MEMORY_GROWTH=1 which allows increasing the size at runtime but prevents some optimizations, (3) set Module.TOTAL_MEMORY to a higher value before the program runs, or (4) if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0
    could this be cause of server settings? apache in macosx
     
  6. TheNerdyBoy

    TheNerdyBoy

    Joined:
    Dec 17, 2020
    Posts:
    2
    This is what worked for me.
    name of project\ProjectSettings\ProjectSettings.asset
    Line 721: webGLEmscriptenArgs: [was blank here]
    added -s ALLOW_MEMORY_GROWTH=1

    Code (CSharp):
    1. webGLEmscriptenArgs: -s ALLOW_MEMORY_GROWTH=1
    Takes a little longer to load, but works.
    Dev Build is unchecked and Code Opt is set to "size"
     
  7. PD36

    PD36

    Joined:
    Jul 9, 2018
    Posts:
    2

    Do you get any solution here? I am facing same error.
    My project was running already, but after some sprite optimization, I got stuck here, it gives me memory error. Please HELP!!!
     
  8. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    944
    Which Unity version are you running on?

    Like Marco mentioned above, memory growth is already enabled by default in Unity builds, but you can try force-enabling it via the webglEmscriptenArgs: -s ALLOW_MEMORY_GROWTH=1 line.

    Also another thing you can try to double check is to edit the ProjectSettings.asset and see if you have a line

    webGLLinkerTarget: 0

    in there. If so, change it to

    webGLLinkerTarget: 1

    That will ensure that the project is doing a wasm build, in case it had been doing an asm.js build before.
     
    leungelvis4 and unjuken like this.
  9. unity_K_nDtRZtMCIVjg

    unity_K_nDtRZtMCIVjg

    Joined:
    Feb 4, 2021
    Posts:
    8
    I have the same issue. When code called first time after few seconds I got "Cannot enlarge memory arrays.".Unity version 2019.4.18. Will try to build with
    PlayerSettings.WebGL.emscriptenArgs = "-s ALLOW_MEMORY_GROWTH=1";

    Code (CSharp):
    1.                 if (_currSaveThread == null)
    2.                 {
    3.                     _currSaveThread = new Thread(() =>
    4.                     {
    5.                         while (true)
    6.                         {
    7.                             lock (_isSaveRequestedInMainThread_Mutex)
    8.                             {
    9.                                 if (_isSaveRequestedInMainThread_Lockable)
    10.                                 {
    11.                                     _isSaveRequestedInMainThread_Lockable = false;
    12.                                     SaveGame(filePath);
    13.                                 }
    14.                             }
    15.                         }
    16.                  
    17.                     });
    18.                     _currSaveThread.Start();
    19.                 }
    20.  
    21.                 lock (_isSaveRequestedInMainThread_Mutex)
    22.                 {
    23.                     _isSaveRequestedInMainThread_Lockable = true;
    24.                 }
    Update
    The same issue but instead I got NULL function call something like that. It seems some Unity related issue.
     
    Last edited: May 31, 2021
  10. unjuken

    unjuken

    Joined:
    Jun 2, 2021
    Posts:
    1
    This fixed the issue in my case!
     
    jukka_j likes this.
  11. fish-rp

    fish-rp

    Joined:
    May 6, 2021
    Posts:
    9
    @jukka_j @Marco-Trivellato I am also experiencing this issue on Unity 2020.3.6f1 I have force-enabled memory growth by adding it to my projecting settings as:

    webglEmscriptenArgs: -s ALLOW_MEMORY_GROWTH=1

    And I have confirmed my project is doing a wasm build with the line:

    webGLLinkerTarget: 1

    Any other ideas?

    Here's my full list of current WebGL settings:
    Code (CSharp):
    1.   webGLMemorySize: 16
    2.   webGLExceptionSupport: 1
    3.   webGLNameFilesAsHashes: 0
    4.   webGLDataCaching: 1
    5.   webGLDebugSymbols: 0
    6.   webGLEmscriptenArgs: -s ALLOW_MEMORY_GROWTH=1
    7.   webGLModulesDirectory:
    8.   webGLTemplate: APPLICATION:Minimal
    9.   webGLAnalyzeBuildSize: 0
    10.   webGLUseEmbeddedResources: 0
    11.   webGLCompressionFormat: 1
    12.   webGLWasmArithmeticExceptions: 0
    13.   webGLLinkerTarget: 1
    14.   webGLThreadsSupport: 0
    15.   webGLDecompressionFallback: 1
    UPDATE: I've resolved my issue thanks to this reported issue: https://issuetracker.unity3d.com/is...-standard-shader-is-always-included-in-builds

    Removing Standard from always included Shaders fixed it.
     
    Last edited: Jun 21, 2021
  12. Giusort

    Giusort

    Joined:
    Jul 7, 2015
    Posts:
    4


    We're facing the same problem on a WebGL glTF viewer using GLTFUtility (https://github.com/Siccity/GLTFUtility); in rendering some detailed glTF file dinamically downloaded from a server (around 150 MB), the browser crashes:

    "Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value 2004156416, (2) compile with..."

    We tryed uselessly all solutions here (ALLOW_MEMORY_GROWTH and so on).

    So, from your suggestion and this one (https://forum.unity.com/threads/webgl-excessive-memory-consumption-1-5gb.622720/) we tryed to check Always Included Shaders list with no lock.


    upload_2021-7-15_15-7-18.png


    Some suggestion?

    Thank you.
     
    travlake likes this.
  13. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,593
    webglEmscriptenArgs: -s ALLOW_MEMORY_GROWTH=1
    worked here!