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. Dismiss Notice

Bug Why emscriptenArgs no longer takes effect in the Unity2021?

Discussion in 'WebGL' started by OceanX000, Dec 7, 2021.

  1. OceanX000

    OceanX000

    Joined:
    Feb 24, 2021
    Posts:
    120
    How to pass the initial memory size of WebAssembly? In the past we could pass TOTAL_MEMORY, but now it seems to have no effect. It can be seen from editor.log that the parameters of the emcc command are not passed in TOTAL_MEMORY.
    Code (CSharp):
    1.  PlayerSettings.WebGL.emscriptenArgs += $" -s TOTAL_MEMORY={totalMemory}MB";
    Why do you want to do this? Our game runs on mobile devices, especially under iOS. When the memory continues to grow 256MB, memory spikes will appear and cause memory crashes. But when the initial value is set, such as 384MB, it will not. Is it because there will be special mechanisms at the bottom of the browser when it continues to grow from 256, such as allocating new space for copying?
    Therefore, we hope that the initial value of memory can be set in the previous Unity version to alleviate this memory crash.
     
  2. OceanX000

    OceanX000

    Joined:
    Feb 24, 2021
    Posts:
    120
    upload_2021-12-7_14-30-30.png
    This is the memory graph in iOS (purple represents memory footprint). When the memory exceeds 1024MB, the game is very prone to memory crash. When the initial memory is set, such memory spikes will not appear.
     
  3. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    334
    This was broken in 2021.2 from the upgrade to the newer emscripten but was fixed. I'll check where the fix landed to make sure it got backported to 2021.2.
     
  4. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    334
    I checked in on this fix, and the update that fixed emscriptenArgs ran into some initial complications and hasn't been pushed out yet. It should be updated soon, and will be fixed in the affected versions, 2021.2+.
     
  5. jowitt_msft

    jowitt_msft

    Joined:
    Feb 11, 2016
    Posts:
    16
    Just hit this today with Unity 2021.2.5f1 - any word on when it'll get fixed?
     
  6. jowitt_msft

    jowitt_msft

    Joined:
    Feb 11, 2016
    Posts:
    16
    Ah, I see you posted your report about an update coming soon, just yesterday. Sorry, looking forward to that update as this is blocking us.
     
  7. jowitt_msft

    jowitt_msft

    Joined:
    Feb 11, 2016
    Posts:
    16
    Are there any known work arounds?
     
  8. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    334
    Unfortunately it requires a change to the underlying build system so there isn't a work-around. The fix was delayed because of some other issues, but it's back in the queue now. Really sorry it's blocking you, it was something that slipped through the cracks with the major Emscripten overhaul.
     
    DrViJ and jowitt_msft like this.
  9. jowitt_msft

    jowitt_msft

    Joined:
    Feb 11, 2016
    Posts:
    16
    Thanks for following up! The WebGL target seems much improved in 2021 otherwise. Fingers crossed for a quick release. We've found a way by modifying the lines in Library/Bee/rsp/<somenumber>.rsp to resolve it on a second build, but no preprocessor seems to get called after that file is generated, but before its contents are used so we can't fix the first run.
     
  10. jowitt_msft

    jowitt_msft

    Joined:
    Feb 11, 2016
    Posts:
    16
    Was able to bind to BuildPlayerWindow.RegisterBuildPlayerHandler and try, fail, detect, patch, try again to work around it in most cases. Still eating that failed first build though and looking forward to the fix coming in!
     
  11. chrisdjali-wrld3d

    chrisdjali-wrld3d

    Joined:
    Apr 23, 2021
    Posts:
    3
    As well as
    emscriptenArgs
    not working in Unity 2021, if that problem's worked around, it's got
    EM_FROZEN_CACHE
    set. This prevents options like
    USE_ZLIB
    being set, as that'd build and cache Emscripten's zlib port, which can't be done if the cache is frozen. Native plugins that use Emscripten's ports need to be able to pass these flags at link time, and it worked in Unity 2019 and 2020.
     
    DrViJ likes this.
  12. OceanX000

    OceanX000

    Joined:
    Feb 24, 2021
    Posts:
    120
    Still keep waiting for fixed.
     
  13. DrViJ

    DrViJ

    Joined:
    Feb 9, 2013
    Posts:
    154
    Does it mean that we cannot use native .a plugins now?
     
  14. etaxi341

    etaxi341

    Joined:
    Oct 4, 2013
    Posts:
    64
    Any news on this topic? I can't find a way to set the Initial Heap Size since upgrading to 2021
     
  15. jowitt_msft

    jowitt_msft

    Joined:
    Feb 11, 2016
    Posts:
    16
    We're still using .a files built with emscripten in Unity WebGL projects without issue (though work arounds needed depending on their content).
     
    DrViJ likes this.
  16. jowitt_msft

    jowitt_msft

    Joined:
    Feb 11, 2016
    Posts:
    16
    Can you confirm is this will be coming with at least 2021.3?
     
  17. OceanX000

    OceanX000

    Joined:
    Feb 24, 2021
    Posts:
    120
    We tested that this property is in effect (starting from 2021.2.11), but I don't know if it also applies to your situation:
    PlayerSettings.WebGL.emscriptenArgs += $" -s TOTAL_MEMORY={totalMemory}MB";
     
    jowitt_msft and DrViJ like this.
  18. chrisdjali-wrld3d

    chrisdjali-wrld3d

    Joined:
    Apr 23, 2021
    Posts:
    3
    Eight months later, and Unity 2021 support for our WebGL plugin is back on the menu. The frozen cache is still making
    -s USE_ZLIB=1
    a hassle. The problem can be worked around by building something with this flag with standalone Emscripten, and then copying the relevant cache entries into the Unity install directory, but this isn't an acceptable solution for our customers to use on their machines.