- Home /
Problem with WWW (Performance Issue)
Hi ,
Am downloading 10 images from server and displaying on my UI flow.
Sometimes app is crashing.
How to reduce the burden of WWW so that app not crash ?
Thank you !!!
Answer by SkaredCreations · Dec 15, 2014 at 09:36 AM
It depends on how you're downloading them, it's better to manage a queue than download all of them simultaneously, for example max 2-3. You could use a Queue and Dequeue items inside a loop.
Ya. At a time am downloading 1 only.
$$anonymous$$y server response is in json format. am splitting the response and downloading an images 1 by 1 with For() loop. Still am getting crashes. (each image size is approx 50-90kb only)
I doubt the downloading is causing the crash, please put the code in your original post of both download and what you're doing later with it.
$$anonymous$$y Code :
First am Checking the image is existed in my persistentDataPath or not? if existed , getting from local data else downloading from the server and saving in a persistent datapath.
for(int g=0;g<10;g++){
if(File.Exists(Application.persistentDataPath + "/"+ ThumbImageName+"_"+ThumbImageTimestamp)){
string URL="file://"+Application.persistentDataPath + "/"+ ThumbImageName+"_"+ThumbImageTimestamp;
WWW wwwArImage = new WWW(URL);
yield return wwwArImage;
if(wwwArImage.isDone && wwwArImage.error == null){
Texture2D ARImage = new Texture2D(250, 250);
ARImage.LoadImage(wwwArImage.bytes);
$$anonymous$$ainArray[g]=ARImage;
}else{
print ("Error !!!");
}
}else{
string ImageURL=N["response"]["data"][g]["subcat_image"];
WWW wwwArImage = new WWW(ImageURL);
yield return wwwArImage;
if(wwwArImage.isDone && wwwArImage.error == null)
{
Texture2D ARImage = new Texture2D(250, 250);
ARImage.LoadImage(wwwArImage.bytes);
$$anonymous$$ainArray[g]=ARImage;
File.WriteAllBytes(Application.persistentDataPath + "/"+ ThumbImageName+"_"+ThumbImageTimestamp, wwwArImage.bytes);
}else{
print("Error");
}
}
Is there a reason why you're creating Texture2D manually ins$$anonymous$$d of use wwwArImage.texture? The reason of a crash could be many, for example if $$anonymous$$ainArray length is lesser than 10 or File.WriteAllBytes fails to write or wwwArImage is not a texture etc. Did you try to check if there's anything in the log?
Ins$$anonymous$$d of creating Texture2D now am using wwwArImage.texture to load image in an array.
Array length is same as number of textures to download. (i never get array index Out of range exception).
for each image, WriteAllBytes will call once in a lifetime. Next time onwards getting an image from local (persistant data path) only.
Thank you.
(crash is random)
Your answer
![](https://koobas.hobune.stream/wayback/20220613174055im_/https://answers.unity.com/themes/thub/images/avi.jpg)