Search Unity

loading 4096 texture causes huge mono heap grow, with 2048 almost no offect on mono heap

Discussion in 'Web' started by pretender, May 10, 2021.

  1. pretender

    pretender

    Joined:
    Mar 6, 2010
    Posts:
    865
    Hi, i have noticed that loading huge custom file that represent compressed texture using UnityWebRequest and creating texture in runtime with it's byte data (using LoadRawTextureData) creates huge mono heap grow that cannot be released. here is the sample code:

    Code (CSharp):
    1. using (var downloadRequest = UnityWebRequest.Get(mainUrl))
    2.             {
    3.                 byte[] bytes= null;
    4.                 yield return downloadRequest.SendWebRequest();
    5.                
    6.                 bytes= new byte[(int)downloadRequest.downloadedBytes - header];
    7.                 Buffer.BlockCopy(downloadRequest.downloadHandler.data, header, bytes, 0, (int)downloadRequest.downloadedBytes - header);
    8.                
    9.                 texture.LoadRawTextureData(bytes);
    10.                 texture.Apply(false, true);
    11.                 texture.wrapMode = TextureWrapMode.Clamp;
    12.                
    13.             }
    14.  
    any ideas?
     
  2. sumpfkraut

    sumpfkraut

    Joined:
    Jan 18, 2013
    Posts:
    242
    De-Panther likes this.
  3. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    why loading as bytes and not using the UnityWebRequestTexture?
    and as sumpfkraut wrote, set nonReadable as true.

    The wasm memory size is limited.
    while some browsers on some platforms can contain large enough memory size for 2048*2048 image, 4096*4096 is too big.

    The UnityWebRequestTexture know how to handle the texture on the JavaScript side, and if you set it as nonReadable, it won't load the byte data to the wasm memory.