Search Unity

WebGL - Mobile Browsers Memory Problems

Discussion in 'Web' started by tiggaxxx, Jul 30, 2021.

  1. tiggaxxx

    tiggaxxx

    Joined:
    Jan 13, 2020
    Posts:
    30
    Hi,

    So recently i started having memory issues on mobile browsers.

    I will leave a print of the error below

    tempsnip.png

    On desktop everything works fine.

    I have tried different Unity versions (2021.1.15, 2020.3.14 and 2019.4.28), and i got memory issues in all of them, despite the messages being a bit different.

    I have tested this on iOS and Android phones with Chrome 92.0.4515.115.

    I have some older builds that work on mobile, and i think i didn't made any major changes that could cause this. I added two new Shaders (Standard and Standard (Specular)) to the always included shaders because of my asset bundles, can it be related?

    Does anyone know a possible cause for this problem? Is it a bug or is it my code?

    EDIT: It works on Firefox 90.1.2

    UPDATE:

    So i tried to remove the two shaders from the Always Included Shaders and the build loaded... but the moment i try to add a piece from my assetbundles (which contains materials using one of thoose shaders), as expected the object appears pink, and i once again get the memory errors.

    EDIT:

    I confirmed the problem was about the Always Included Shaders, found another user who had the same issue: https://forum.unity.com/threads/webgl-excessive-memory-consumption-1-5gb.622720/

    And the optimal solution i found was the suggested here: https://forum.unity.com/threads/asset-bundles-and-shaders.806331/

    After solving this i got another related issue. I create base64 images based on the textures to send them outside unity (for thumbnails and stuff). And for this i have to duplicate the Texture2D to have writing permissions, as i have to decompress and compress again with a costume script.

    Seem like Unity can't handle Texture creation in realtime on mobile platforms, as i have had an similar issue before trying to use a photo taken by the user as a background.
     
    Last edited: Jul 30, 2021
  2. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    The WASM module has a buffer/HEAP which is a one large TypedArray, in which it stores all it's data/memory.
    It's size is limited, as you can see from the error, and browsers don't notify about it gracefully.

    Editing textures can occupy all the HEAP very fast.
    So if you need to edit textures on web, better do this on JavaScript or an external WASM module.

    It's a limitation of the browsers...