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

via testflight beta, we’re seeing an infrequent crash in WWWConnection.mm,
on this line:

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

others are seeing this as well:

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.

woohoo!
many thanks Aurimas-Cernius! this is great.

i’ll add this to the “answers” thread as well.

Howdy -

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

@property (readonly, retain, nonatomic) NSURLConnection*    connection;

i assume they should both be modified ?

Yes, that is correct, though it seems enough to only modify the .mm file.

got it. thanks.

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.

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.

Do you have a reliable way to reproduce the problem ?
It’s quite rare for us.

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.

Looks like 5.6.3p4 has just arrived and should fix this issue :slight_smile:

@Aurimas-Cernius Thanks for the solution. Which version of Unity 2017 should we expect the solution in?

@GAMEDIA_Justin We’re using the following iOS PostBuild script to replace the overriden files. Just place in the appropriate folder and add a “.override” to the .mm filename. Should work with Cloudbuild.

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:

@property (strong, atomic)               NSCondition*          condition;

Anyone know what could be causing it?

edit: added crash log

3421801–270029–Crash March 12.txt (115 KB)

The attached pdf file looks blank page to me.

@Aurimas-Cernius Sorry about that, updated the file with a .txt version that seems to be working

It apparently shouldn’t matter, but what about the same declaration in WWConnection.h ?

There is none O.o

3422796--270119--Screen Shot 2018-03-13 at 10.23.10 AM.png

From the looks of it I think the WWWConnection gets destroyed before this call. Which version are you on? Looks a pretty old one.

@Aurimas-Cernius I’m using Unity 2017.2 and Xcode 9.2