Hello all.
After upgrading the use of “WWW” to “UnityWebRequest” (wich is annoying btw) I’m running into a “problem” (not much a problem) here.
I use this rutine of UnityWebRequest for download texts and Images Like this:
IEnumerator GetBytes(string path, string ext)
{
UnityWebRequest.ClearCookieCache();
//writesuccess = false;
HashSet<string> set = new HashSet<string>() { ".png", ".jpg", ".jpeg", ".bmp" };
if (set.Contains(ext))
{
www = UnityWebRequestTexture.GetTexture("file://" + path);
DownloadHandlerTexture texDl = new DownloadHandlerTexture(true);
www.downloadHandler = texDl;
//yield return www.SendWebRequest();
www.SendWebRequest();
while (!www.isDone)
{
Debug.Log(www.downloadProgress);
//yield return null;
}
yield return new WaitUntil(() => www.downloadHandler.isDone);
Debug.Log("Imagen descargada exitosamente");
//while (!www.downloadHandler.isDone)
//{
// Debug.Log("Coping File");
// yield return null;
//}
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
//image.texture = DownloadHandlerTexture.GetContent(www);
results = www.downloadHandler.data;
resultImgOK = true;
Debug.Log(results.Length);
}
}
else
{
www = UnityWebRequest.Get("file://" + path);
//yield return www.SendWebRequest();
www.SendWebRequest();
while (!www.isDone)
{
Debug.Log(www.downloadProgress);
//yield return null;
}
Debug.Log(www.isDone);
yield return new WaitUntil(() => www.downloadHandler.isDone);
Debug.Log("Archivo descargado exitosamente");
//while (!www.downloadHandler.isDone)
//{
// Debug.Log("Coping File");
// yield return null;
//}
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
//writesuccess = false;
}
else
{
results = www.downloadHandler.data;
//writesuccess = true;
if (lastPath)
resultGLTFOK = true;
Debug.Log(results.Length);
}
}
}
Downloading texts works fine,the problem is that when in comes the time to download a image Unity freezes at all (with no bugs) and I have to force the close.
BUT!! if I change the “www.SendWebRequest();” line by “yield return www.SendWebRequest();” (commented in this code) everything works fine. I don’t use the last because I want to handle and monitor the download proccess in case of large images.
So I can use the “yield return www.SendWebRequest()” but I want to know what causes Unity yo freeze with “www.SendWebRequest();”
Thank you in advance.
Saludos!!.