Search Unity

[5.3.1p1] WWW.isDone hangs in iOS

Discussion in 'iOS and tvOS' started by AlienMe, Jan 1, 2016.

  1. AlienMe

    AlienMe

    Joined:
    Sep 16, 2014
    Posts:
    93
    It seems that WWW.isDone broke in 5.3.1. This used to work fine in 5.2

    This code hangs in iOS:

    Code (csharp):
    1.  
    2. private IEnumerator DownloadFile( string url )
    3. {
    4.     var www = new WWW( url );
    5.  
    6.     while ( !www.isDone )
    7.     {
    8.         Debug.Log( "Never gets here" );
    9.         yield return null;
    10.     }
    11. }
    12.  
    When running on iOS, the call to www.isDone doesn't return. If I pause the game in XCode, and resume execution.. then it works fine.

    Doing the usual yield return www works fine.
     
  2. Elkis

    Elkis

    Joined:
    Jun 15, 2013
    Posts:
    87
    Similar to this issue: My code used to work fine in 5.3.0 and in 5.3.1f1 and 5.3.1p1 WWW never returns from yield:

    Code (CSharp):
    1. public IEnumerator fetchImageAtUrl( string url, Action<Texture2D> completionHandler )
    2. {
    3.      var www = new WWW( url );
    4.    
    5.      yield return www;
    6.      Debug.Log("Never gets here");
    7.  
    8.      if( !string.IsNullOrEmpty( www.error ) )
    9.      {
    10.            Debug.Log( "Error attempting to load profile image: " + www.error );
    11.            if( completionHandler != null )
    12.                completionHandler( null );
    13.      }
    14.      else
    15.      {
    16.           if( completionHandler != null )
    17.               completionHandler( www.texture );
    18.      }
    19. }
     
  3. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Can one or both of you try this with the Mono scripting backend to see if the behavior is similar? I'm not familiar with any known issues like this, but in the past we have corrected a few IL2CPP runtime bugs related to similar code. I'm curious to help narrow down the cause of this issue.
     
  4. AlienMe

    AlienMe

    Joined:
    Sep 16, 2014
    Posts:
    93
    In our case, it happened with the Mono scripting backend.. didn't test it with IL2CPP.

    Currently we switched to a third party http solution (BestHTTP), will switch back later.
     
  5. rain03

    rain03

    Joined:
    Apr 18, 2014
    Posts:
    5
    Just put together a sample project with the following code:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class test : MonoBehaviour
    5. {
    6.     WWW www;
    7.     // Use this for initialization
    8.     void Start ()
    9.     {
    10.         www = new WWW("http://www.google.com");
    11.     }
    12.    
    13.     // Update is called once per frame
    14.     void Update ()
    15.     {
    16.         if (www != null && Time.frameCount % 5 == 0)
    17.         {
    18.             Debug.LogFormat("www.isDone: {0}",www.isDone);
    19.             Debug.LogFormat("www.error: {0}",www.error);
    20.             Debug.LogFormat("www.text: {0}",www.text);
    21.         }
    22.     }
    23. }
    24.  
    I compiled it with both mono2x and IL2CPP and the output was the same(repeating forever):
    www.isDone: False
    UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
    UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    UnityEngine.Logger:LogFormat(LogType, String, Object[])
    UnityEngine.Debug:LogFormat(String, Object[])


    www.error:
    UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
    UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    UnityEngine.Logger:LogFormat(LogType, String, Object[])
    UnityEngine.Debug:LogFormat(String, Object[])


    UnityException: WWW is not ready downloading yet
    at UnityEngine.WWW.get_text () [0x00000] in <filename unknown>:0
     
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @rain03

    Thanks for building this example. Can you file a bug report so that we can track it? Thanks.
     
  7. Elkis

    Elkis

    Joined:
    Jun 15, 2013
    Posts:
    87
    I tried reproducing the issue on new projects to file a bug report but failed. Seems everything works fine when creating new projects; must be something specific to the project I'm working on that is causing the issue.

    Anyway, I found a workaround suggested by another user in this thread, so I guess everything is all right now.

    Thank you :)
     
  8. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @Elkis

    Thanks, I'm glad you could work around the issue. We have been able to reproduce this with some versions of Unity internally, so our iOS team is looking into a fix now.
     
    Elkis likes this.
  9. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    I'm having the same issue right now. I first tried 5.3.1p2 first, but no success. Next I tried the 5.3.0 workaround, but this also didn't work for me. Seems like the workaround is not working for everybody, so if there would be a hotfix available, please post it.
     
  10. Elkis

    Elkis

    Joined:
    Jun 15, 2013
    Posts:
    87
    Yes! I saw Christopher commenting about it on the other thread! Thank you :)

    @pahe Did you try replacing the WWWconnection.mm file from the Xcode project with another from a previous 5.3.x project that works?
     
  11. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    @Elkis Yes, I used the WWWconnection.mm file from 5.3.0, but it didn't work with that version. The last version I'm sure it worked with is 5.2.3, but reverting back to that version is... a lot of work with the scene management change.

    Also tested the WWW class from 5.3.1f1 and 5.3.1p2, but non of those worked. :/

    I'm trying to download assetbundles with it, waiting for .isDone before returning it. Works fine on all other platforms, but iOS.
     
  12. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    @JoshPeterson do you know if the iOS team has already found what the problem is? If it's possible to fix with just altering the WWWConnection.mm file, I could do it by myself. Would be great to know, as we're kind of stuck right now. Reverting back to 5.2.x would be much work for us, though we're considering it currently.
     
  13. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hi @pahe,
    I have made a fix for the issue on this thread which causes unity to hang. Unfortunately the fix touches files outside of the trampoline project. I can work to try and find a workaround that will get you unblocked, otherwise you will have to wait for the next patch release. I will get back to you soon.
    Thanks,
    Chris
     
  14. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hello @pahe,
    I am unable to reproduce WWW causing a deadlock with WWW.isDone with 5.3.1p2. Could you give me additional information about which version of xcode/ios you are using. Also could you make sure that you have a clean install of unity? I have confirmed that calling WWW.Dispose does cause an issue in the thread I had mentioned in my previous post.
    Thanks,
    Chris
     
    pahe likes this.
  15. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    Thanks and sure, I'll try tomorrow again and make a fresh install with 5.3.1p2.
     
  16. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hey @pahe,
    I have actually reproduced this. It seems to happen when a redirect occurs. I wasn't seeing it because all of the URLs I was trying were .com URLs :). I will test this against my changes for the issue in this thread and let you know the results. I will also see if I can create a workaround for you.
    Cheers,
    Chris
     
    Elkis likes this.
  17. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hi @pahe,
    I have attached a file that will allow redirects to continue working. This does not fix the WWW.Dispose deadlock. I have tested this against the scripts that have been posted here. Please let me know if this helps you work around this issue.
    Thanks,
    Chris
     

    Attached Files:

    pahe and Elkis like this.
  18. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    @christophergoy First, thanks for your effort! I checked your new WWWConnection.mm and I can confirm following things:

    1. original 5.3.1p2 WWW didn't work for us.
    2. your posted WWWConnection.mm did fix the downloading problem for downloads from web.
    3. your posted WWWConnection.mm doesn't work for local file requests (i.e. file:///).

    I'm not sure if that wasn't working with the original WWW file too, as we have the following process in our app:
    1. download text file from web (a file which stores assetbundle versions).
    2. download assetbundles by checking first if it is on the local disk and else download it from web.

    Code (CSharp):
    1.  
    2.         Debug.Log("TryToLoadFromDisk: " + StreamingAssetPath + anAssetName + " Version: " + anAssetbundleInfo.version);
    3.  
    4.         var aLocalAssetWWW = new WWW(StreamingAssetPath + anAssetName);
    5.    
    6.         //Wait for the WWW to be initialized
    7.         Debug.Log("TryToLoadFromDisk: Wait for the WWW to be initialized");
    8.         yield return aLocalAssetWWW;
    9.  
    10.         Debug.Log("TryToLoadFromDisk: WWW is initialized, now wait for isDone");
    11.  
    12.         while (!aLocalAssetWWW.isDone)
    13.         {
    14.             Debug.Log("TryToLoadFromDisk: Wait for the WWW. Is done: " + aLocalAssetWWW.isDone);
    15.             yield return aLocalAssetWWW;
    16.         }
    17.  
    This code runs till the "yield return aLocalAssetWWW;" and stops then on iOS.

    TryToLoadFromDisk: file:////var/mobile/Containers/Bundle/Application/<appnamehash>/<appname>.app/Data/Raw/2_1_2/iOS/Atlases/gearicons.assetbundle Version: 8
    <tryToLoadAssetFromDisk>d__4:MoveNext()
    ResourceLoader:loadAssetBundle(String, String, AssetbundleInfo, AssetBundleResourceLoadedCallback, Object[])
    PreLoadingScreenViewController:loadAtlasAssetBundles(Single)
    <loadAssetBundles>c__Iterator60:MoveNext()

    TryToLoadFromDisk: Wait for the WWW to be initialized
    <tryToLoadAssetFromDisk>d__4:MoveNext()
    ResourceLoader:loadAssetBundle(String, String, AssetbundleInfo, AssetBundleResourceLoadedCallback, Object[])
    PreLoadingScreenViewController:loadSingleAtlas(String, Boolean)
    PreLoadingScreenViewController:loadAtlasAssetBundles(Single)
    <loadAssetBundles>c__Iterator60:MoveNext()
    (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
     
  19. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    Hey @christophergoy,
    I commented out the part of simply returning the www and now it works also on iOS. So, there seems to be a change then in the WWWConnection class which breaks our code.
     
  20. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hi @pahe,
    Let me make sure I understand. WWW works for files on the web, but not local files if you use
    Code (CSharp):
    1. yield return aLocalAssetWWW;
    If you don't use the yield return it works?
    Thanks,
    Chris
     
  21. amjaliks

    amjaliks

    Joined:
    Jul 11, 2015
    Posts:
    159
    Last edited: Jan 12, 2016
  22. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    Simply replace the file in your xCode project under Classes/Unity/ should do the trick.

    Yes and yes. :)
     
    amjaliks likes this.
  23. amjaliks

    amjaliks

    Joined:
    Jul 11, 2015
    Posts:
    159
    Fine. I get it. I just need to replace this file in Xcode project. But it doesn't help with redirects. :(
     
  24. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hi @amjaliks,
    Can you give me an example of a redirect that is not working for you? The change I made was specifically for redirects.
    Thanks,
    Chris
     
  25. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hi @pahe,
    Could you post a small repro project so I can debug this?
    Thanks,
    Chris
     
  26. amjaliks

    amjaliks

    Joined:
    Jul 11, 2015
    Posts:
    159
    I try to get profile pictures from Facebook:

    Code (csharp):
    1. IEnumerator LoadPictures(List<string> ids) {
    2.     foreach (string id in ids) {
    3.         if (!pictures.ContainsKey(id)) {
    4.             WWW request = new WWW("https://graph.facebook.com/v2.4/" + id + "/picture?type=square");
    5.             yield return request;
    6.  
    7.             if (request.error == null && request.texture != null) {
    8.                 pictures[id] = Sprite.Create(request.texture, new Rect(0,0, 50, 50), new Vector2());
    9.             }
    10.         }
    11.     }
    12. }
    Concrete URL: https://graph.facebook.com/v2.4/100000479582531/picture?type=square.

    The same code works fine on Android. And it worked on iOS with previous Unity versions (5.1 and 5.2).
    Now I work with 5.3.1p2.
     
  27. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hey @amjaliks,
    I'll take a look at this and get back to you.
    Thanks,
    Chris
     
  28. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hi @pahe and @amjaliks,
    I apologize. I uploaded the wrong file :p. I have attached a file that correctly handles redirects. Please try this file out and let me know if this fixes your issue. I have tested it with the script you have posted @amjaliks
    Cheers,
    Chris
     

    Attached Files:

    pahe and amjaliks like this.
  29. amjaliks

    amjaliks

    Joined:
    Jul 11, 2015
    Posts:
    159
    Yep, now it works as expected. Thanks! :)
     
  30. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    @christophergoy
    I can confirm that also your new WWWConnection class can download from web, but still is not running through the yield return www;

    I'll try to create a small repro project for you and post the case number then.
     
  31. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    @pahe,
    Where are you calling your coroutine from? I have seen behavior like this if I try to call a coroutine directly from the Update method. If that is the case you can use the StartCoroutine() function to call your own. Here is my example script that I have working at the moment.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class test : MonoBehaviour
    5. {
    6.     WWW request = null;
    7.     float timeElapsed = 5.0f;
    8.     void Start()
    9.     {
    10.     }
    11.  
    12.     void Update()
    13.     {
    14.         timeElapsed += Time.deltaTime;
    15.         if (timeElapsed >= 5.0f)
    16.         {
    17.             timeElapsed = 0;
    18.             StartCoroutine(loadTexture());
    19.         }
    20.     }
    21.  
    22.     IEnumerator loadTexture()
    23.     {
    24.         request = new WWW("https://graph.facebook.com/v2.4/100000479582531/picture?type=square");
    25.         yield return request;
    26.  
    27.         if (!request.isDone)
    28.         {
    29.             Debug.Log("Request is not finished");
    30.             yield return null;
    31.         }
    32.         else if (request.error == null && request.texture != null) {
    33.             Debug.Log ("We loaded the texture just fine");
    34.         } else {
    35.             Debug.Log ("There was an error loading the texture");
    36.             Debug.Log("Error: " + request.error);
    37.             Debug.Log("Texture: " + request.texture);
    38.         }
    39.     }
    40. }
    41.  
    Please let me know if this isn't what you are experiencing.
    Thanks,
    Chris
     
  32. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    @christophergoy

    The problem seems only affecting local file requests and then yield returning the WWW. I created a test project for you (c: 761361) to test it.
    Sorry for the messed up loader, but it was a bit complicated to remove the other stuff. Essentially the "tryToLoadAssetFromDisk" function is the point where the code hangs later.
     
  33. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    @pahe,
    Thanks I'll check it out and see what I can do.
    Thanks,
    Chris
     
  34. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    @pahe,
    I have confirmed this as a bug. Thanks for your repro project. Unfortunately the change for this is outside of the iOS Trampoline code and will be in a future release. I will inform you here when it is ready to go out. Thanks everyone very much for your patience and your input. Just to recap:
    1. Redirects were an issue
      1. The fix is in Trampoline WWWConnection posted here
    2. yield return WWW for local files seems to hang
      1. The fix will be coming in a patch release soon
    Thank you,
    Chris
     
    Novack, HereIAmItsMe and pahe like this.
  35. aixa

    aixa

    Joined:
    Sep 28, 2012
    Posts:
    46
    Hi, I have also similar problem with Asset bundles loading from cache. When I load asset bundles with function WWW.LoadFromCacheOrDownload() for the first time it works, but when the code is trying to get them from cache - isDone is never called and app gets stuck and crashes.

    Here I posted a thread and there are also logs:
    http://forum.unity3d.com/threads/ios-asset-bundle-crash-on-decompression-in-unity-5-3-1p3.380558/
    I’m using Unity 5.3.1p3.

    I’m not sure if there is a problem because we call WWW.LoadFromCacheOrDownload() from Update(), and we check in Update() for isDone to happen. Would this be fixed if we would use Cooroutine and yield instead?

    I have also replace the WWWConnection file in XCode, but the issue still stays.

    In Unity 5.2 the same code is working fine.
     
    Last edited: Jan 20, 2016
  36. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    hi @aixa,
    It sonds like your issue is similar to the one that is happening in this thread. I'm hoping to land the fix this week. I'll will keep this thread updated when it happens.
    Thanks,
    Chris
     
    aixa likes this.
  37. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hi @aixa @pahe,
    Could you try this file. I think I may have found a workaround without you having to wait for a patch release. Here is a new WWWConnection.mm to try
    Cheers,
    Chris
     

    Attached Files:

    aixa and pahe like this.
  38. aixa

    aixa

    Joined:
    Sep 28, 2012
    Posts:
    46
    Hi,
    I have tried this morning, but unfortunatly it's still not fixed for the local files that I'm trying to get from cache. What is actually the problem with the www class?
     
  39. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
  40. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    hi @aixa,
    Could you file a bug with a repro project? There is another bug where if WWW.dispose() is called, there is a deadlock. This fix is coming in a patch release.
    Thanks,
    Chris
     
  41. abrechin

    abrechin

    Joined:
    Apr 29, 2014
    Posts:
    2
    A new patch is out today 5.3.1p4
    I can't see anything in the build notes for these issues?
     
  42. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hi @abrechin,
    Your observation is correct. My fix is still moving, albeit, slowly through the submission process. Were you able to try the WWWConnection.mm that was posted here to see if it solves your issue?
     
  43. aixa

    aixa

    Joined:
    Sep 28, 2012
    Posts:
    46
    I have submitted the bug report - Case 765304
     
  44. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
  45. jnbt

    jnbt

    Joined:
    Jul 8, 2013
    Posts:
    11
  46. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hello @andymads, @jnbt,
    The changes are going in the final review process and will going into a patch release soon. I will tentatively say 5.3.2p3.

    @aixa thanks!
     
  47. aixa

    aixa

    Joined:
    Sep 28, 2012
    Posts:
    46
  48. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    @aixa great! Would you mind updating your bug for me?
    Thanks,
    Chris
     
  49. subbu5280

    subbu5280

    Joined:
    Oct 1, 2015
    Posts:
    5
    @aixa based on your replay i also tried to use Unity 3D 5.3.2p1, But my end its not solved.i am facing same issue., Even when i replaced WWWConnection.mm no use in 5.3.2 p1.
     
    Last edited: Feb 5, 2016
  50. amsmntparks

    amsmntparks

    Joined:
    May 20, 2009
    Posts:
    19
    I had to replace WWWConnection.mm in 5.3.2p2 as well. @christophergoy can you confirm that the bug hasn't reappeared?