Hello. I’m developing an exhibition app with Unity WebGL. I’ve decided to load Images with UWP(UnityWebRequest) to reduce my first loading time. Because my base app is 70MB. All images are smaller than 2048x2048px in real size. And file sizes are 300-500kb. The average total size of the pictures is ~200MB. Everything is looking reasonable according to today’s internet speed. But somehow, my internet browser(Opera) gives an Memory Allocation Error when loading my images in to Unity WebGL app. It says that error:
WebGL.framework.js:3338 Could not allocate memory: System out of memory!
Trying to allocate: 5805543B with 16 alignment. MemoryLabel: Texture
Allocation happened at: Line:70 in ./Runtime/Utilities/dynamic_array.h
Memory overview
[ ALLOC_TEMP_THREAD ] used: 32768B | peak: 0B | reserved: 4194304B
[ ALLOC_TEMP_JOB_1_FRAME ] used: 0B | peak: 0B | reserved: 262144B
[ ALLOC_TEMP_JOB_2_FRAMES ] used: 0B | peak: 0B | reserved: 262144B
[ ALLOC_TEMP_JOB_4_FRAMES ] used: 0B | peak: 0B | reserved: 1048576B
[ ALLOC_TEMP_JOB_ASYNC ] used: 15440582B | peak: 0B | reserved: 17039360B
[ ALLOC_DEFAULT ] used: 50305651B | peak: 57639027B | reserved: 51652762B
[ ALLOC_GAMEOBJECT ] used: 393738B | peak: 926820B | reserved: 419199B
[ ALLOC_GFX ] used: 2014771894B | peak: 2014771894B | reserved: 2014809667B
[ ALLOC_PROFILER ] used: 866833B | peak: 4453539B | reserved: 970108B
I’m not getting what is the problem. This numbers are huge according to my 200mb(204800B) images. Here is my script:
public IEnumerator GetImage(string mainURL, string imageFileName, System.Action<Texture2D> callback = null)
{
//print(url + imageFileName);
using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(mainURL + imageFileName))
{
yield return uwr.SendWebRequest();
if (uwr.result == UnityWebRequest.Result.ConnectionError || uwr.result == UnityWebRequest.Result.ProtocolError || uwr.result == UnityWebRequest.Result.DataProcessingError)
{
Debug.Log(uwr.error + "\n" + imageFileName + " is missing!");
yield return null;
}
else
{
Texture2D texture = DownloadHandlerTexture.GetContent(uwr);
callback?.Invoke(texture);
uwr.Dispose();
yield return null;
}
yield return null;
}
yield return null;
}
Is anyone can explain to me what is the problem. Am I facing some kind of technical limit or doing something wrong?