- Home /
 
WebGL memory issue when using WWW to Download Images.
Hello guys,
The error happens when try to download a image from AWS server using WWW.
This topic may be recurrent, but I've not found a solution for this specific issue.
This is a quiz game with text and images questions, and i believe the error present where the code tries to download the image. Here a part of the code:
 if(!string.IsNullOrEmpty(question.image_url))
 {
       loadingBarImg.fillAmount = 0;
       percentageTxt.text = "0%";
 
       //Debug.Log("Downloading image, from quesiton ID: "+question.id);
       wwwQuestion = new WWW(question.image_url);
       while (!wwwQuestion.isDone)
       {
              percentageTxt.text = Mathf.Round(wwwQuestion.progress*100)+"%";
              loadingBarImg.fillAmount = wwwQuestion.progress;
       }
 
       yield return wwwQuestion;
 
       question.questionImage = Utils.BytesToSprite(wwwQuestion.bytes);
 }
 
               Error presented on normal Build:

Error presented on development Build: (Sorry this one is in Portuguese (BR))

Any help or hint would be good. :)
Answer by Bunny83 · Sep 18, 2017 at 03:00 PM
This loop:
 while (!wwwQuestion.isDone)
 {
     percentageTxt.text = Mathf.Round(wwwQuestion.progress*100)+"%";
     loadingBarImg.fillAmount = wwwQuestion.progress;
 }
 
               will crash your app. Read this page, especially the section:
Do not block on WWW or WebRequest downloads
What should work is this:
 while (!wwwQuestion.isDone)
 {
     percentageTxt.text = Mathf.Round(wwwQuestion.progress*100)+"%";
     loadingBarImg.fillAmount = wwwQuestion.progress;
     yield return null;
 }
 
              Bunny83, thanks for reply. I didn't know that.
Actually, today I solved the problem using UnityWebRequest ins$$anonymous$$d of WWW (class). $$anonymous$$aybe this help someone too.
Cheers.
Your answer
 
             Follow this Question
Related Questions
Free memory after WWW.LoadImageIntoTexture 1 Answer
calling www to get audio.clip multiple times causes memory problems 1 Answer
Unity WWW download crash in CompressedFileStream(out of memory) 1 Answer
WebGL memory size in Player Settings? 2 Answers
WebGL Build Out of Memory Github Pages Not on Local Host 0 Answers