Search Unity

iOS: UnityWebRequest crash in WWWConnection.mm : WaitOnCondition()

Discussion in 'iOS and tvOS' started by elenzil, Sep 14, 2017.

  1. elenzil

    elenzil

    Joined:
    Jan 23, 2014
    Posts:
    73
    via testflight beta, we're seeing an infrequent crash in WWWConnection.mm,
    on this line:

    Code (csharp):
    1.  
    2. static void WaitOnCondition(UnityWWWConnectionDelegate* delegate)
    3. {
    4.     NSCondition *condition = delegate.condition;
    5.     [condition lock];          <-------------------------- crash
    6.     [condition wait];
    7.     [condition unlock];
    8. }
    others are seeing this as well:
    https://answers.unity3d.com/questions/1390673/ios-crashing-on-unitywebrequest-calls.html
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    This bug has been fixed and we're shipping it in patch releases. However, the fix is very trivial and you can do it yourself without risking an upgrade: in the same file find a definition for UnityWWWConnectionDelegate and remove the 'nonatomic' flag from the condition property.
     
  3. elenzil

    elenzil

    Joined:
    Jan 23, 2014
    Posts:
    73
    woohoo!
    many thanks Aurimas-Cernius! this is great.

    i'll add this to the "answers" thread as well.
     
  4. elenzil

    elenzil

    Joined:
    Jan 23, 2014
    Posts:
    73
    Howdy -

    this declaration actually occurs in two places:
    WWConnection.h and WWConnection.mm both have this line:

    Code (csharp):
    1. @property (readonly, retain, nonatomic) NSURLConnection*    connection;
    i assume they should both be modified ?
     
  5. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    Yes, that is correct, though it seems enough to only modify the .mm file.
     
  6. elenzil

    elenzil

    Joined:
    Jan 23, 2014
    Posts:
    73
    got it. thanks.
     
  7. GAMEDIA_Justin

    GAMEDIA_Justin

    Joined:
    Mar 29, 2017
    Posts:
    19
    We're having the same problem. But you need to remove nonatomic from NSCondition* condition, not NSURLConnection* connection. And that's only in WWWConnection.mm.

    When can we expect a Unity patch for this? We're using Cloud Build, which makes it harder to remove the nonatomic.
     
  8. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    Which release are you using. This fix so far has been backported to 5.6 and newer, patch releases with the fix are not yet out, but are being tested now.
     
  9. elenzil

    elenzil

    Joined:
    Jan 23, 2014
    Posts:
    73
    Do you have a reliable way to reproduce the problem ?
    It's quite rare for us.
     
  10. GAMEDIA_Justin

    GAMEDIA_Justin

    Joined:
    Mar 29, 2017
    Posts:
    19
    We use 5.6.3f1. We might upgrade to 2017 if that one gets the patch first.

    Unfortunately, no. It just randomly happens sometimes when I switch view. Our Unity project is more an app than a game. We have to do a bunch of request to retrieve all images and data. Maybe it's related, but every time we close a view, we do Resources.UnloadUnusedAssets.
     
    Last edited: Sep 22, 2017
  11. GAMEDIA_Justin

    GAMEDIA_Justin

    Joined:
    Mar 29, 2017
    Posts:
    19
    Looks like 5.6.3p4 has just arrived and should fix this issue :)
     
  12. sapanda

    sapanda

    Joined:
    Oct 3, 2016
    Posts:
    3
    @Aurimas-Cernius Thanks for the solution. Which version of Unity 2017 should we expect the solution in?
     
  13. sapanda

    sapanda

    Joined:
    Oct 3, 2016
    Posts:
    3
  14. totsboy

    totsboy

    Joined:
    Jul 12, 2013
    Posts:
    253
    I'm using Unity 2017.2 and I have this issue, crashing for ~8% of the player base.
    Looked on WWWConnection.mm and the property is like this, so should be working I guess:
    Code (CSharp):
    1. @property (strong, atomic)               NSCondition*          condition;
    Anyone know what could be causing it?


    edit: added crash log
     

    Attached Files:

  15. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    The attached pdf file looks blank page to me.
     
  16. totsboy

    totsboy

    Joined:
    Jul 12, 2013
    Posts:
    253
    @Aurimas-Cernius Sorry about that, updated the file with a .txt version that seems to be working
     
  17. elenzil

    elenzil

    Joined:
    Jan 23, 2014
    Posts:
    73
    It apparently shouldn't matter, but what about the same declaration in WWConnection.h ?
     
  18. totsboy

    totsboy

    Joined:
    Jul 12, 2013
    Posts:
    253
    There is none o_O
     

    Attached Files:

  19. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    From the looks of it I think the WWWConnection gets destroyed before this call. Which version are you on? Looks a pretty old one.
     
  20. totsboy

    totsboy

    Joined:
    Jul 12, 2013
    Posts:
    253
  21. elenzil

    elenzil

    Joined:
    Jan 23, 2014
    Posts:
    73
    It's coming from inside the house !
     
  22. CharlesBarros

    CharlesBarros

    Joined:
    Nov 17, 2011
    Posts:
    61
    Is this fix necessary in Unity 2017.4.1f1?
     
  23. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    can anyone comment what is the ticket number for this? what release has the fix for it? and whether the workaround (remove nonatomic) fixes the crash? @Aurimas-Cernius
     
  24. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    If you get crash exactly at the point of condition lock, then yes, removing nonatomic would fix that. Note that this condition has been removed in later releases. I believe 2017.4 should work fine (and this is the oldest one we still support).