- Home /
iOS Unity randomly hangs on yield return www
I'm developing an iOS app with Unity where I load textures at runtime from the file system. I only have one scene. The piece of code I use to load the textures is shown below. This is called several times during runtime if the user wishes to change these so called 'backTextures'.
In my tests I call this several times in a row. Everything goes well and afaik there is no sign of memory leaks. But after executing this several random times (say as little as 2 times or even as much as 13 times for example) Unity hangs.
According to the Xcode console, the last print I read is the 'Just created the www' so I am assuming the script is hanging waiting for the 'yield return _www;'. This happens always on the first iteration of the for loop (i=0), but as I said before, after calling this piece of code several times.
Can anyone help me out with this? I have no idea why yield return www would hang...
EDIT I did some more testing: This code is running on a coroutine. I added a print to the Update() and it keeps being called. So the Unity engine is not completely dead. It really seems that it is the www that is not returning....
//some code before
if(backTextures != null && backTextures.Length != 0){
Debug.Log("Cleaning the vector!!!!");
for(int i = 0; i < backTextures.Length; i++){
Destroy(backTextures[i]);
backTextures[i] = null;
}
}
//Some more code here
Debug.Log("Will load " + picsize + " textures");
//load textures to memory
for(int i=0; i<picsize; i++){
Debug.Log("Let's read the texture " + i);
string _textureURL = "file://" + Application.dataPath + "/../../Documents/current/" + imageNames[i];
Debug.Log("The path is " + _textureURL);
WWW _www = new WWW(_textureURL);
Debug.Log("Just created the www");
yield return _www;
Debug.Log("Returned from yield return");
if (_www.error != null)
{
Debug.LogError("WWW Error: "+ _www.error);
i--;
_www.Dispose();
_www = null;
continue;
}else{
Debug.Log("There was no error!!!!!");
}
Debug.Log("Will assign textures");
backTextures[i] = _www.texture;
Debug.Log("Will dispose textures");
_www.Dispose();
_www = null;
}
// some code after
How can you solve it ? I have met the same problem as you