Android Crash because of dynamic sprite loading over a coroutine
Dynamic loading of sprites in coroutine results in a failure to allocate memory on Android. OutOfMemory Exception thrown despite plenty of memory being available
We analysing currently how many images it works before it crashed. Between 100-1000 images
Unity Version: Unity 2019.4.6f1 LTS
The implementation was carried out as follows:
using (var request = UnityWebRequestTexture.GetTexture("file:///" + DataManager.Instance.DataPath + fileName))
{
yield return request.SendWebRequest();
if (request.isNetworkError || request.isHttpError)
{
Debug.Log($"Error loading image: {request.error}");
image.sprite = null;
onCompleted.Invoke();
}
else
{
Sprite sprite = null;
var texture = DownloadHandlerTexture.GetContent(request);
sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
Comment
Your answer
Follow this Question
Related Questions
Waiting for Saving/Loading? 2 Answers
Loading a sprite from URL C# 3 Answers
Anima2d Crashes on game exit consisently. 0 Answers
Coroutines and loading screens 1 Answer
[HDRP][MEMORY LEAK] Unity crashes when reaching maximal possible ram space 0 Answers