Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

A workaround for the "yield return www" hang on iOS

Discussion in 'iOS and tvOS' started by liortal, Aug 31, 2015.

  1. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    Hey,

    Today I have encountered a serious issue with Unity and the WWW class (using 5.1.2p3)

    In case there's no network connectivity, the following code hangs:
    Code (CSharp):
    1. yield return www; // hangs !!!
    This occurs on iOS only AFAIK.

    Here's a post on my blog with a simple workaround (until there's a fix in the next patch release): www.tallior.com/workaround-for-www-yield-bug/
     
  2. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    541
    Hey @liortal

    I can see this bug also in 5.2.0f3. Do you have made a bugreport already for this one?
     
  3. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    Are you sure ?

    This is said to be resolved in 5.1.2p3 . maybe these changes are not rolled into 5.2 yet ?
     
  4. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    541
    Well, not 100% sure that it is this problem, but the following code will never hit the last debug output on 5.2.0f1, but on 5.1.2f1:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class downloader : MonoBehaviour {
    5.  
    6.     private IEnumerator startDownload(WWW aDownload)
    7.     {
    8.         var sec = 0f;
    9.         Debug.Log("start download");
    10.  
    11.         Debug.Log(aDownload.isDone);
    12.  
    13.         while (!aDownload.isDone && sec < 10f)
    14.         {
    15.             sec += Time.deltaTime;
    16.             Debug.Log(aDownload.isDone + " Caching: " + Caching.ready);
    17.  
    18.             yield return aDownload;
    19.         }
    20.  
    21.  
    22.         if (sec >= 10f) {
    23.             Debug.Log("security timeout");
    24.         }
    25.  
    26.         yield return aDownload;
    27.  
    28.         Debug.Log("download ended: " + aDownload.error + ". sec: " + sec + ". Caching: " +  Caching.ready);
    29.     }
    30.  
    31.     // Update is called once per frame
    32.     void OnGUI ()
    33.     {
    34.  
    35.         if (GUI.Button (new Rect(100, 100, 100, 100), "start"))
    36.         {
    37.             StartCoroutine(startDownload(new WWW("http://www.noexistant.com/myAsset.asset")));
    38.         }
    39.     }
    40. }
    41.  
    Now I've got the test project (which took me 30 minutes, while finding that it is something here took me a few days :( ) and I can create a bug report for Unity.


    Update: Case 727455
     
    Last edited: Sep 14, 2015
  5. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    This looks pretty similar to my issue. That was fixed for 5.1.2p3 so maybe it will be merged into 5.2 in the first patch that will be released...

    Have you tried the code i posted as a workaround ?
     
  6. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    541
    Yes, I tried that and it worked for the yield return aDownload. But then the Caching.ready is always false, which I need for the assetbundles. The code is working in 5.1.2f1, but not in 5.2.
     
  7. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    if the download fails, Caching.ready should return false right? isn't this the case here ?
     
  8. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    541
    Caching.ready only shows if caching of assetbundles is possible at all. So, if it's not, WWW.LoadFromCacheOrDownload will always download the assetbundles new. That's not the behaviour I want to have for my 20 mb assetbundles ^^ For smaller packages it could work, but this function has the intention to work with the caching.
     
  9. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    541
    Update on this: the fix should be in 5.2.0p1. The QA tested it with the test project and it didn't appear there again. So just wait for the patch release.
     
    liortal likes this.
  10. matbrummitt

    matbrummitt

    Joined:
    Jan 12, 2010
    Posts:
    107
    Any idea how long these patches usually take? I am experiencing the same issue and my game relies on having an internet connection so I really need this update.

    At what point are these patch releases considered to be a normal version that will work with the web player?

    Thanks

    Mat
     
  11. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    Patches come out usually around once a week or so. Not sure how it'll go with the newly released version (5.2).
     
  12. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    541
    The 5.2.0p1 should come this week, but don't nail me on that ;)
     
    liortal likes this.
  13. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    5.2.0p1 is out now, so this should solve the issue, in case you've been waiting for it :)
     
  14. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    5.2.0p1 is out now with the fix :)
     
  15. omrip32

    omrip32

    Joined:
    Jan 4, 2016
    Posts:
    105
    This still happens to me on Unity 5.2.4 :(
     
  16. omrip32

    omrip32

    Joined:
    Jan 4, 2016
    Posts:
    105
    On galaxy tab s7