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

Unity 5.3. iOS. Application hangs. WWW deadlock when loading a texture.

Discussion in 'iOS and tvOS' started by Andrey-Postelzhuk, Dec 14, 2015.

  1. Andrey-Postelzhuk

    Andrey-Postelzhuk

    Joined:
    Nov 26, 2013
    Posts:
    75
    After update to Unity 5.3 We've got a deadlock on iOS.
    WWW class works fine for simple http requests. But there is a deadlock during loading a texture with WWW class. Probably it's happens because I manually call Dispose().
    Here is a call stack:
     
  2. Andrey-Postelzhuk

    Andrey-Postelzhuk

    Joined:
    Nov 26, 2013
    Posts:
    75
    Confirmed. This is definitely happens because of calling Dispose in WWW.
     
  3. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
    Hi, could you submit a bug report and attache a simple reproduction project to it? Please post the bug number here. Thanks!
     
  4. Andrey-Postelzhuk

    Andrey-Postelzhuk

    Joined:
    Nov 26, 2013
    Posts:
    75
    Hi. This is my first bug report that I've created yesterday: 753977_lioosj0cg583a8uk

    This is bug report that I've just created with steps to reproduce and test project: 754382_6haafsmbq3l2kdfk
     
    Last edited: Dec 15, 2015
  5. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
  6. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hello Andrey,
    We recently made some changes to the WWW class that should fix this deadlock that will be release in the first patch release of 5.3. I tested out your project today and I was unable to get a deadlock with these changes. Thanks for submitting your project. Please let us know if you experience this again in the patch release. Thanks.
     
  7. Andrey-Postelzhuk

    Andrey-Postelzhuk

    Joined:
    Nov 26, 2013
    Posts:
    75
    Thanks Christopher. I'll install patch release and check it.
     
  8. Andrey-Postelzhuk

    Andrey-Postelzhuk

    Joined:
    Nov 26, 2013
    Posts:
    75
  9. XiaoJi

    XiaoJi

    Joined:
    Jul 5, 2013
    Posts:
    15

    i find a new bug is 5.3.1, the ios http can't work , i revert the WWWconnection.mm.it work.
    is it safe to revert ??
     
    Elkis likes this.
  10. Elkis

    Elkis

    Joined:
    Jun 15, 2013
    Posts:
    87
    I'm getting exactly the opposite behavior: WWW class worked fine on 5.3.0 and it never returns from yield when loading a texture on 5.3.1f1 or 5.3.1p1

    Edit: Just wanted to thank XiaoJi! I wasn't able to downgrade to 5.3.0 anymore so reverting the wwwconnection.mm file worked as a charm :)
     
    Last edited: Jan 3, 2016
  11. Andrey-Postelzhuk

    Andrey-Postelzhuk

    Joined:
    Nov 26, 2013
    Posts:
    75
    @XiaoJi @Elkis Did you report a bug?
    When I reported a bug with example project Unity team fixed it in 24 hours.
     
  12. Elkis

    Elkis

    Joined:
    Jun 15, 2013
    Posts:
    87
    Since the project that presented the bug is very big, I tried to replicate the behavior on a new project. I don't know why but I am unable to reproduce it, WWW class is working fine on new projects.

    I guess it might be some other plugin causing this or the fact that I've been upgrading this project since 5.2 that is causing this issue.

    Anyway, since new projects work fine and I got a workaround for this particular project, I guess all is good :)
     
  13. Andrey-Postelzhuk

    Andrey-Postelzhuk

    Joined:
    Nov 26, 2013
    Posts:
    75
    I wrote new test application for WWW.Dispose() and report a bug.
    Deadlock steel exists.
    I've tested this script for iOS, android, editor.
    There is a deadlock for iOS.
    Script works with lags (0.5 - 1 seconds) for android.
    And script crashes in editor.

    Here are test script:
    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class TestWWW : MonoBehaviour
    6. {
    7.  
    8.     private WWW mWWW;
    9.     private int mDisposeCounter;
    10.     private int mDisposeThreshold;
    11.     private bool mSuccess;
    12.  
    13.     private GUILayoutOption mMinWidth;
    14.     private GUILayoutOption mMinHeight;
    15.  
    16.     void Awake()
    17.     {
    18.         mMinWidth = GUILayout.MinWidth(400);
    19.         mMinHeight = GUILayout.MinHeight(150);
    20.     }
    21.    
    22.     // Update is called once per frame
    23.     void Update()
    24.     {
    25.         if (mWWW != null)
    26.         {
    27.             if (mWWW.isDone)
    28.             {
    29.                 mWWW.Dispose();
    30.                 mWWW = null;
    31.                 mSuccess = true;
    32.             }
    33.             else
    34.             {
    35.                 ++mDisposeCounter;
    36.                 if (mDisposeCounter > mDisposeThreshold)
    37.                 {
    38.                     ++mDisposeThreshold;
    39.                     Debug.Log("Dispose: " + mDisposeCounter);
    40.                     mWWW.Dispose();
    41.                     CreateWWW();
    42.                 }
    43.             }
    44.         }
    45.     }
    46.  
    47.     void OnGUI()
    48.     {
    49.         if (mWWW != null)
    50.         {
    51.             GUILayout.Label(string.Format("In progress: {0}, {1}", mDisposeCounter, mDisposeThreshold), mMinWidth, mMinHeight);
    52.         }
    53.         else
    54.         {
    55.             GUILayout.Label("Success: " + mSuccess, mMinWidth, mMinHeight);
    56.             if (GUILayout.Button("Create Request", mMinWidth, mMinHeight))
    57.             {
    58.                 mDisposeThreshold = 0;
    59.                 CreateWWW();
    60.                 mWWW.Dispose();
    61.                 CreateWWW();
    62.             }
    63.         }
    64.     }
    65.  
    66.     private void CreateWWW()
    67.     {
    68.         mWWW = new WWW("http://google.com");
    69.         mDisposeCounter = 0;
    70.     }
    71. }
    72.  
     
    Elkis likes this.
  14. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hi Andrey,
    I will test your script out. Could you tell me the bug number for this?
    Thanks,
    Chris
     
  15. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hi Andrey,
    I have confirmed that the deadlock still exists with your script posted.. I am currently fixing it. I will update your bug accordingly once you give me the case number.
    Thanks,
    Chris
     
  16. Andrey-Postelzhuk

    Andrey-Postelzhuk

    Joined:
    Nov 26, 2013
    Posts:
    75
    Hi, Chis! Thanks for quick reply. The bug number is 759480.
     
  17. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Great! Thanks.
     
  18. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hi Andrey,
    I have a fix going through our review process. Once I know which release it will get into, I will notify you here. Thanks again for your repro script, it was helpful in uncovering this.
    Cheers,
    Chris
     
    Andrey-Postelzhuk likes this.
  19. wgt_jimmy

    wgt_jimmy

    Joined:
    Dec 22, 2014
    Posts:
    39
    This did not get into 5.3.1p3, did it?
     
  20. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hi @wgt_jimmy,
    No unfortunately it did not. I am trying to target the next patch release. I will confirm when I know.
    Thanks,
    Chris
     
  21. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    @Andrey Postelzhuk ,
    Could you try to replace your current WWWConnection with this one attached and see if it works?
    Thanks,
    Chris
     

    Attached Files:

  22. Andrey-Postelzhuk

    Andrey-Postelzhuk

    Joined:
    Nov 26, 2013
    Posts:
    75
    @christophergoy, I replaced WWWConnection in generated XCode project. Behaviour is the same. Deadlock still exists. Maybe this is because I changed test script. Here is the final version:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Experimental.Networking;
    3. using System.Collections;
    4.  
    5. public class TestWWW : MonoBehaviour
    6. {
    7.  
    8.     private UnityWebRequest mWebRequest;
    9.     private WWW mWWW;
    10.     private int mDisposeCounter;
    11.     private int mDisposeThreshold;
    12.     private bool mSuccess;
    13.     private bool mUseWebRequests;
    14.  
    15.     private GUILayoutOption mMinWidth;
    16.     private GUILayoutOption mMinHeight;
    17.  
    18.     void Awake()
    19.     {
    20.         mMinWidth = GUILayout.MinWidth(400);
    21.         mMinHeight = GUILayout.MinHeight(150);
    22.     }
    23.    
    24.     // Update is called once per frame
    25.     void Update()
    26.     {
    27.         if (hasActiveRequest)
    28.         {
    29.             if (requestIsDone)
    30.             {
    31.                 DisposeRequest();
    32.                 mSuccess = true;
    33.             }
    34.             else
    35.             {
    36.                 ++mDisposeCounter;
    37.                 if (mDisposeCounter > mDisposeThreshold)
    38.                 {
    39.                     ++mDisposeThreshold;
    40.                     Debug.Log("Dispose: " + mDisposeCounter);
    41.                     DisposeRequest();
    42.                     CreateRequest();
    43.                 }
    44.             }
    45.         }
    46.     }
    47.  
    48.     void OnGUI()
    49.     {
    50.         if (hasActiveRequest)
    51.         {
    52.             GUILayout.Label(string.Format("In progress: {0}, {1}", mDisposeCounter, mDisposeThreshold), mMinWidth, mMinHeight);
    53.         }
    54.         else
    55.         {
    56.             GUILayout.Label("Success: " + mSuccess, mMinWidth, mMinHeight);
    57.             mUseWebRequests = GUILayout.Toggle(mUseWebRequests, "Use Web Request", mMinWidth, mMinHeight);
    58.             if (GUILayout.Button("Create Request", mMinWidth, mMinHeight))
    59.             {
    60.                 mDisposeThreshold = 0;
    61.                 CreateRequest();
    62.                 DisposeRequest();
    63.                 CreateRequest();
    64.             }
    65.         }
    66.     }
    67.  
    68.     private void CreateRequest()
    69.     {
    70.         if (mUseWebRequests)
    71.         {
    72.             mWebRequest = UnityWebRequest.Get("http://google.com/");
    73.             mWebRequest.Send();
    74.         }
    75.         else
    76.         {
    77.             mWWW = new WWW("http://google.com/");
    78.         }
    79.         mDisposeCounter = 0;
    80.     }
    81.  
    82.     private void DisposeRequest()
    83.     {
    84.         if (mWebRequest != null)
    85.         {
    86.             mWebRequest.Abort();
    87.             mWebRequest.Dispose();
    88.             mWebRequest = null;
    89.         }
    90.         if (mWWW != null)
    91.         {
    92.             mWWW.Dispose();
    93.             mWWW = null;
    94.         }
    95.     }
    96.  
    97.     private bool requestIsDone
    98.     {
    99.         get
    100.         {
    101.             if (mUseWebRequests)
    102.             {
    103.                 return mWebRequest.isDone;
    104.             }
    105.             else
    106.             {
    107.                 return mWWW.isDone;
    108.             }
    109.         }
    110.     }
    111.  
    112.     private bool hasActiveRequest
    113.     {
    114.         get
    115.         {
    116.             if (mUseWebRequests)
    117.             {
    118.                 return mWebRequest != null;
    119.             }
    120.             else
    121.             {
    122.                 return mWWW != null;
    123.             }
    124.         }
    125.     }
    126. }
    127.  
    I tried to use new UnityWebRequest. It works with this test script. But when I inserted UnityWebRequest in our real project, game was always crashing in editor.
     
    Last edited: Jan 22, 2016
    christophergoy likes this.
  23. Appxplore

    Appxplore

    Joined:
    Oct 2, 2015
    Posts:
    26
    Hi,

    I found that somehow when i want to load a facebook profile picture through WWW class, it doesn't work and always return 400 bad request. I had submit a bug report and wish to know is anyone has the same problem? It only happens in iOS Unity3d 5.3.1p1 and p3(I didn't try others).

    The bug report i file is : 761206_0rjp4s67u5rciurs
    together i had attached the project in the bug report. Only happens in device(iOS 9.2 in iPad 3 Wifi, i haven't tested others).

    Thank you.
     
  24. Andrey-Postelzhuk

    Andrey-Postelzhuk

    Joined:
    Nov 26, 2013
    Posts:
    75
    @Appxplore Did you try the same url in a browser? Post the code example with hardcoded url I'll try it.
     
  25. Appxplore

    Appxplore

    Joined:
    Oct 2, 2015
    Posts:
    26
    @Andrey Postelzhuk
    below are the code: when i build into my ipad, i never successfully see profile pic.

    Code (CSharp):
    1. using UnityEngine;
    2. using System;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using System.Runtime.InteropServices;
    6.  
    7. public class TestFb : MonoBehaviour
    8. {
    9.     public SpriteRenderer m_sprite;
    10.     protected Texture2D        m_texture;
    11.     protected string        m_message;
    12.  
    13.     // Use this for initialization
    14.     void Start ()
    15.     {
    16.         StartCoroutine(loadPic());
    17.     }
    18.  
    19.     IEnumerator loadPic()
    20.     {
    21.         string _pic = "https://graph.facebook.com/v2.1/100001293360646/picture?height=80&width=80";
    22.  
    23.         WWW www = new WWW( _pic );
    24.         Debug.Log("run URL: "  + _pic);
    25.  
    26.         yield return www;
    27.  
    28.         Debug.Log("run done!");
    29.  
    30.         if( !string.IsNullOrEmpty( www.error ) )
    31.         {
    32.             Debug.Log( "Error attempting to load profile image: " + www.error );
    33.             m_message = "Error occurs!";
    34.         }
    35.         else
    36.         {
    37.             m_texture = www.texture;
    38.         }
    39.     }
    40.  
    41.     void OnGUI()
    42.     {
    43.         if(m_texture != null)
    44.             GUILayout.Label(m_texture);
    45.         else
    46.             GUILayout.Label(m_message);
    47.     }
    48. }
     
  26. Andrey-Postelzhuk

    Andrey-Postelzhuk

    Joined:
    Nov 26, 2013
    Posts:
    75
    @Appxplore Bug reproduces for me too (Unity version 5.3.1f1). Script works in editor but on device coroutine never finishes.
     
  27. Appxplore

    Appxplore

    Joined:
    Oct 2, 2015
    Posts:
    26
    I already file the bug, I just dunno when this will be solved. This is important for me since I'm using facebook friends' profile pictures as one of my game feature and it doesn't work now!
     
  28. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
  29. Appxplore

    Appxplore

    Joined:
    Oct 2, 2015
    Posts:
    26
    Hi @christophergoy, I had try your solution and it seems that that fixed the problem :) wait for your patch to be release ASAP. thank you.
     
  30. Dragonic89

    Dragonic89

    Joined:
    Jan 3, 2013
    Posts:
    48
    Hello,

    May I ask if my current problem with WWW request is the same as the bug mentioned here ? I have problems to make it working on iOS devices.

    I need to check Internet connection on the device before initializing UnityAds, because of this case : http://forum.unity3d.com/threads/ad-not-ready-and-data-connection.381577/

    I launch this script at the start of the application :

    Code (CSharp):
    1.  public IEnumerator checkInternetConnection()
    2.     {
    3.         float t1 = Time.fixedTime;
    4.         while(!StaticDatas.adsInitialized)
    5.         {
    6.             WWW www = new WWW(System.Uri.EscapeUriString("http://www.google.com/"));
    7.             t1 = Time.fixedTime;
    8.             yield return www;
    9.             if (www.error == null)
    10.             {
    11.                 StaticDatas.adsInitialized = true;
    12.                 if (Advertisement.isSupported) // If the platform is supported,
    13.                 {
    14.                     #if UNITY_ANDROID
    15.                     Advertisement.Initialize(StaticDatas.androidGameID); // initialize Unity Ads.
    16.                     #elif UNITY_IOS
    17.                     Advertisement.Initialize(StaticDatas.iosGameID); // initialize Unity Ads.
    18.                     #endif
    19.                 }
    20.                 #endif
    21.                 break;
    22.             }
    23.  
    24.             if(Time.fixedTime - t1<2.0f)//every two seconds min
    25.                 yield return new WaitForSeconds(2.0f-(Time.fixedTime - t1));
    26.         }
    27.     }
    No problem in Editor and Android, but on iOS devices it never reach "Advertisement.Initialize".
    (stuck on yield, tested on iPad iOS 9.2, using Cloud Build with Unity 5.3.1f1 for the current build)

    The WWWConnection fix is for XCode , isn't it ? I can't use that, I have to use the Cloud Build functionnality to create the binary for iOS !

    Is there another way to secure an Internet connection check on iOS without a third party plugin until a fix ?

    EDIT : finally the "Advertissement.IsReady" bug ( http://forum.unity3d.com/threads/ad-not-ready-and-data-connection.381577/ ) doesn't occur on iOS for me (maybe the problem is only for Android). So I don't need to use the WWW class in my iOS build. Problem resolved for me ! (that don't change the fact that I can't use WWW for now on iOS devices, and if I need it later it will be a problem ^^)
     
    Last edited: Feb 2, 2016
  31. fafase

    fafase

    Joined:
    Jul 3, 2012
    Posts:
    160
    I am actually seeing the issue with 5.3.2p2 latest patch from Feb 3rd.

    I have removed all www.Dispose and I still see the problem.

    If I build with a 5.0 version it goes fine.

    Is this supposed to be fixed? I am confused as some old posts say it would be done quickly.

    The used code is fairly simple and gets stuck at the WWW call. I remember putting some debug before the yield and it would not call.

    The code below contains Dispose but I tried with and without.

    Code (CSharp):
    1. private IEnumerator CheckOnlineConnection()
    2.     {
    3.         WWW www = new WWW("http://www.google.com");
    4.         yield return www;
    5.         if  (www.error != null)
    6.         {
    7.             www.Dispose ();
    8.             yield break;
    9.         }
    10.         www.Dispose ();
    11.     }
     
    Last edited: Feb 10, 2016
  32. sbergen

    sbergen

    Joined:
    Jan 12, 2015
    Posts:
    51
    As noted above, this bug is reproducible with a simple "yield return www;" from a coroutine. Reported a week ago as bug number 767775. We've narrowed it down to being present in any version > 5.3.0f4.
     
  33. fafase

    fafase

    Joined:
    Jul 3, 2012
    Posts:
    160
    For some reasons, the code works on iPhone 6 but hangs on iPhone5.
     
  34. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hi all,
    Fixes for this problem will be released with 5.3.2p4.
    Thanks,
    Chris
     
    Andrey-Postelzhuk and fafase like this.
  35. teemukorh

    teemukorh

    Joined:
    Oct 28, 2014
    Posts:
    49
    I'm still experiencing this problem with 5.3.3p1... Any ideas or is there regression??

    In release notes there's a mention
    • (759480) - iOS: Fix for WWWConnection deadlock.
     
  36. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hi @teemukorh,
    Can you give more details about what you are seeing? Do you have a small repro project that you can submit with a bug report?
    Thanks,
    Chris
     
  37. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    We are on Unity 5.3.2p3, started seeing weird behaviour with the WWW class.

    It seems like it deadlocks in the WWWConnection.mm class, inside this function:

    static void WaitOnCondition(UnityWWWConnectionDelegate* delegate)
    {
    NSCondition *condition = delegate.condition;
    [condition lock];
    [condition wait];
    [condition unlock];
    }

    If we pause the debugger in xcode and then resume, it will unlock and continue fine.

    Is this the fixed deadlock bug ? if so, can we apply the fix without upgrading to the latest Unity ?
     
  38. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hey @liortal,
    The fixes for this issue went into 5.3.2p4. Changes had to be made outside of the trampoline project so unfortunately you will need to upgrade to the 5.3.2p4 patch release. Or 5.3.3
    Cheers,
    Chris
     
  39. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    Thanks.

    I managed to fix our deadlock issue by avoiding the call to www.Dispose() for now... it seemed to cause a deadlock that froze the game (note that this only occurred when the request times out). Not sure this is a separate bug from the one that was fixed...
     
  40. ESG-Steven

    ESG-Steven

    Joined:
    Mar 18, 2015
    Posts:
    38
    I'm getting an odd behaviour where I am experiencing no bug on my end, while another engineer is experiencing this hanging bug on his end. Both of us are using 5.3.3f1. Is this bug consistent or does this randomness line up with this bug.
     
  41. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hey @liortal,
    The deadlock on dispose was fixed along with some other deadlock issues in 5.3.2p4 (and later).

    Hi @ESG-Steven,
    The bug was very consistent. Can you make sure that the other developer has a clean install of unity and a fresh xcode project that is generated? If the issue still persists please let me know by filing a bug with your repro project and post the case number here. That way I can help you as soon as possible.
    Cheers,
    Chris
     
  42. ESG-Steven

    ESG-Steven

    Joined:
    Mar 18, 2015
    Posts:
    38
    hey @christophergoy yeah a clean install of unity did the trick. Not sure what happened but just reinstalling fixed it D=