Search Unity

5.0.0f4 Memory Issues

Discussion in 'Web' started by MRKane, Mar 12, 2015.

  1. MRKane

    MRKane

    Joined:
    Oct 4, 2012
    Posts:
    54
    Having had a flick through the forums I couldn't find a solution for this so decided to post. I have a very large commercial project that had a working WebGL deployment in beta 22, however upon upgrading to f4 I've had three days of issues with no success.

    Essentially it seems to be a memory issue, or an issue with memory being thrown by something else that's causing the problem. If I set the WebGL Memory size to 512 or higher I get the errors:

    As a popup:
    The browser could not allocate enough memory for the WebGL content. If you are the developer of this content, try allocating less memory to your WebGL build in the WebGL player settings.

    And in the developer console:
    increasing TOTAL_MEMORY to 637534208 to be more reasonableindex.html:33 Module.printErrVolvoDevGLBuild.js:1 (anonymous function)
    Uncaught RangeError: Invalid array buffer lengthVolvoDevGLBuild.js:1 (anonymous function)


    However dropping the memory settings below 512 gives me the corresponding issues in the console:
    increasing TOTAL_MEMORY to 318767104 to be more reasonableindex.html:33 Module.printErrVolvoDevGLBuild.js:1044 (anonymous function)
    index.html:33 run() called, but dependencies remain, so not runningindex.html:33 Module.printErrVolvoDevGLBuild.js:3947268 runVolvoDevGLBuild.js:3947379 (anonymous function)
    index.html:33 pre-main prep time: 296 msindex.html:33 Module.printErrVolvoDevGLBuild.js:3947288 doRunVolvoDevGLBuild.js:3947304 (anonymous function)

    Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value 318767104, (2) compile with ALLOW_MEMORY_GROWTH which adjusts the size at runtime but prevents some optimizations, or (3) set Module.TOTAL_MEMORY before the program runs.


    It's become a real rock and a hard place here and I really don't want to drop back to a beta version of Unity 5, plus the project is a bit too large for me to be able to submit it as a bug report.

    All suggestions appreciated!
     
  2. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    Your build is failing with memory set to below 512 MB, because the project needs more memory. This is expected for large projects.

    Your build is failing with memory set to 512MB or higher, because the browser cannot allocate that much memory. That is not so much expected for modern browsers, however, how much memory you can use in practice does depend on your browser and your hardware (so, please let us know what you are using).

    For instance, I have no issues running projects with up to 2047 MB of memory on Firefox 64 bit on my mac. OTOH, If I try to run content on my iPhone 5s in Safari (which is not really supported anyways), anything >256 MB will fail. 512MB should be possible on most current desktop browsers, however, 32-bit Chrome for instance may be problematic even with that, especially if you have a lot of other things going on in the browser or your machine has a low amount of memory.
     
  3. MRKane

    MRKane

    Joined:
    Oct 4, 2012
    Posts:
    54
    I've tested it on a couple of systems including both 32 and 64 bit, iMac and also some of the powerhouse PCs we've got with 16 gig of ram. What I cannot get my head around is that it worked fine on all systems for a build in the beta release of Unity but not the retail and wondered if there was a new setting somewhere that I may have missed which was causing this or not cleaning up memory, for instance: problems with stacking coroutines, simultaneous WWW class downloads or forced garbage collection.

    We were hoping to replace the obsolete Unity web plugin deployment with the WebGL, which previously did not exceed 256MB at runtime - is it a matter of burning the build down to a sustainable size for WebGL?
     
  4. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    So, if you have tested on a couple of different setups and browsers, did you get the same issue of all of them when exporting with 512MB? Or was it limited to some setups?
     
  5. MRKane

    MRKane

    Joined:
    Oct 4, 2012
    Posts:
    54
    Yes I have tested it across different setups and the errors are consistent.

    You'll have to forgive me my shortsightedness demonstrated in the prior posts and here's why:

    One thing I tried this morning was pointing the computers at my IP instead of using a server, which resulted in slower load times - which also gave a few clues to what was going on. Our programme loads a lot of geographical data after the main Unity side starts up, and it appears to be during one of the loading segments that the memory issues have been happening. At present we're loading several files (none in excess of 1MB but all compressed binary data) via coroutine handled WWW classes and my gut is saying that something is happening within one of these, but it'll take some more checking to see if I can narrow down which.

    I guess that comes back to nested coroutines and the WWW class, is there anything untoward that jumps out at you there?
     
  6. gear

    gear

    Joined:
    May 11, 2009
    Posts:
    35
    I have similar issue with Unity5p1. I am making Fastest(very slow build), the java script file generated is around 110.4 MB. When i run the game in browser its start consuming huge amount of memory. Its taking around 7.5 GB. Here is the screenshot of while game is running in Firefox. In chrome is crashes above 6 GB.



    I am facing other issue related to bundle caching, log say caching bundle to some path, but when i load game next time it start download bundle again.

    Any suggestion on this.

    Thanks
     
  7. DaMitch

    DaMitch

    Joined:
    Feb 6, 2013
    Posts:
    29
    I have the same issue with my project too. The generated webgl.js file is around 168 MB with fastest build, and I have an out of memory exception with a webgl memory size of 2047 MB.
    I tried to build the game only with the default scene (so no custom scripts nor references to custom assets), and the same issue occured.
    The strange thing is, the complet game was working with a beta build of unity 5.0 and a memory size of 1024 MB, and I don't think I changed a lot of things in my project.

    Edit: I lowered the webgl memory size and now the game launches.. I guess I misunderstood how the webgl memory size worked
     
    Last edited: Mar 23, 2015
  8. gear

    gear

    Joined:
    May 11, 2009
    Posts:
    35
    Try this

    Stripping level = any value other than disabled (as its 1 or 0 for WebGL)
    Enable Exception = None or Explicitly ...
    set DISABLE_EXCEPTION_CATCHING with the help of script, below is the code snippest

    Code (CSharp):
    1.   PlayerSettings.SetPropertyString("emscriptenArgs", "-s
    2.  PlayerSettings.SetPropertyString("emscriptenArgs", "-s DISABLE_EXCEPTION_CATCHING=0", BuildTargetGroup.WebGL);
    3. =0", BuildTargetGroup.WebGL);
    4.  
    After this the build memory has reduce drastically. There is one issue for first run game start with very low FPS but second run everything run fine.

    Thanks
     
  9. hyperhippo

    hyperhippo

    Joined:
    Jan 16, 2014
    Posts:
    37
    @jonas echterhoff : I've seen you mention these emscriptenArgs in a few different threads back in the beta forums etc, and now here, and even that cxa_throw console.log option...

    can these be added to the build settings for the webgl platform?

    to me it really seems like for such a problematic platform, there are way more options for helping developers debug that people can't find unless they go digging through forum posts.
     
  10. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    @hyperhippo Setting DISABLE_EXCEPTION_CATCHING like gear printed above can already be done through the Player Settings, not sure why you would override it using emscriptenArgs like this?

    As for adding a console.log into cxa_throw, I think it should just always do that. This is not our code but emscripten's but I will submit a pull request to emscripten to add this, I think it makes a lot of sense.
     
  11. hyperhippo

    hyperhippo

    Joined:
    Jan 16, 2014
    Posts:
    37
  12. MRKane

    MRKane

    Joined:
    Oct 4, 2012
    Posts:
    54
    So after a heap of searching and painful build/check cycles I was able to narrow the problem to the construction of a Vector2 list, as well as some other issues with WebGL not being able to do bitwise operations (but that's another thread topic). It kind of pointed towards perhaps needing some garbage collection or a change of method type (i.e. I might try putting things into an array if I can estimate how many values will be required). Will post back when I've had more time on this :)
     
  13. DrRocker87

    DrRocker87

    Joined:
    Sep 12, 2012
    Posts:
    3
    I am also have a LOT of memory issues. WebGL Memory = 2047, Release File size = 15.9MB and Chrome/Safari/Firefox all die with a "out of memory" warning. Also, Chrome dev tools says I am missing WebGL.js in the release folder, but I have a UnityLoader.js, am I missing a file?
     
  14. alexsuvorov

    alexsuvorov

    Unity Technologies

    Joined:
    Nov 15, 2015
    Posts:
    327
    Hello DrRocker87.

    If you expect your build to run in 32-bit Chrome, you probably should not use heap larger than 1GB, for example, 768MB would be quite reasonable.

    The 404 error you are getting for the .js file is expected. It should just cause the loader to download the .jsgz file and fallback to JavaScript decompression. The build should work just fine.

    The initial request to the missing .js gives you ability to configure your server in such a way that the .jsgz will be served instead of the requested .js with the content-encoding: gzip header appended, so that the decompression can be performed by the browser, which is a bit faster. This is an optional functionality, so you may just safely ignore the initial 404 error for the .js file.
     
  15. IbrahimMahmoud

    IbrahimMahmoud

    Joined:
    Jul 22, 2013
    Posts:
    2
    Hello,

    When I created the first build I had the error several times and I read in the last comment on this post about using memory size of 768MB and it worked perfectly!

    In the next day, I made some edit to the project (but nothing that changes the size dramatically), and then I tried to make the build but I have been receiving the same error over and over the past 3 days. I am using Firefox. I tried MANY different memory sizes and if the size is less than 400MB the browser crashes. If the size is more than 400MB I get this error when it try to load:

    An error occured running the Unity content on this page. See your browser's JavaScript console for more info. The error was:
    NS_ERROR_OUT_OF_MEMORY:

    Then if I refresh the page, the error message changes to:

    The browser could not allocate enough memory for the WebGL content. If you are the developer of this content, try allocating less memory to your WebGL build in the WebGL player settings.

    Actually, my project has around 30 JPEG images the size range is 5 to 12 MB each. I tried disabling most of them before making the build just to test if this could work, but the same error appeared.

    I searched several times for a solid solution for this problem but I could not find any. All what I am doing now is changing the WEBGL memory size in the player settings, I have the feeling it is matter of guessing the correct size.

    Note: I tried most of the numbers that are multiples of 32.

    Console displays:

    uncaught exception: out of memory (unknown)
    NS_ERROR_OUT_OF_MEMORY: ............ fileloader.js:205:0
    cacheRemotePackage() ...................... fileloader.js:205
    runWithFS/</</<() ................................ fileloader.js:259
    fetchRemotePackage/xhr.onload() ....................... fileloader.js:72

    Successfully compiled asm.js code (loaded from cache in 148ms)
     
  16. IbrahimMahmoud

    IbrahimMahmoud

    Joined:
    Jul 22, 2013
    Posts:
    2
    I was able to resolve the problem after reading this and this. Actually, by resizing the textures for WebGL build. Thanks.
     
  17. AlexeySim

    AlexeySim

    Joined:
    Jan 30, 2014
    Posts:
    8
    Hello! I stuck with the decision of this problem :(
    Firefox and Chrome users regularly report about browser could not allocated anouh memory. I spend a lot of time on profiling and optimization my game but system memory usage not change.

    Unity Heap - 32 mb
    Dlls - 266 mb RAM - is it normal? ) if i disable all injections what size will be just Unity dlls ?
    Objects - 128 mb - how i can decrease that?
    Assets - 93 mb
     
  18. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    Did you profile the Editor ? If so, you should launch your WebGL content with "Autoconnect Profiler" option enabled.

    What's the size of WebGLMemorySize and the generated code and data ?
     
  19. AlexeySim

    AlexeySim

    Joined:
    Jan 30, 2014
    Posts:
    8
    Yes, it was editor profiler tab :3
    But my big problem stay. It is 600-700 mb RAM in simple game on Webgl build

    Generated data files:

    upload_2016-9-13_17-24-3.png
     
  20. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    Could you try to grab a memory snapshot from Firefox ?
    - Developer Tools->Memory Tab
    - Take Snapshot
    - Save it
    - post it here :)
     
  21. AlexeySim

    AlexeySim

    Joined:
    Jan 30, 2014
    Posts:
    8
  22. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    there is 87.89 MB of webaudio audiobuffer.
    thanks for your credit card details, it's very generous of you ;)

    two things that stand out:
    - 208mb Unity Heap
    - 87.89mb webaudio audiobuffer

    those seem to be the biggest contributors to your browser memory usage. You could save some memory by reducing WebGLMemorySize, and by playing compressed audio using the html <audio> tag, instead of Unity's audio implementation (which uncompresses audio in memory due to WebAudio limitations)
     
    yuliyF likes this.
  23. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,598
    Given that especially on 32 bit systems there is always a possibility of not having enough memory is there an elegant way to trap this event and pop up a message to the user to close some tabs to free it up?