iOS UnityReportWWWReceivedData crash

Hey,

We’re seeing this crash below semi frequently in our game built with Unity 5.1.1p1, IL2CPP, and universal ARM v7/64-bit.

I think this is a bug that happens some times when using the WWW class. We’re using it quite frequently in our game.

Seems to happen at random locations when fetching JSON text data from the web.

Is anybody else seeing the same crash?

Incident Identifier: 35890B7C-AC42-4790-A43C-12A7E4A0DFBA
CrashReporter Key:   3c7a5d093e3074b1b594640ac5bb731d8df140ef
Hardware Model:      iPad5,3
Version:             2.1.5 (2.1.5)
Code Type:           ARM-64 (Native)
Parent Process:      launchd [1]

Date/Time:           2015-07-07 10:59:51.307 +0200
Launch Time:         2015-07-07 10:58:33.722 +0200
OS Version:          iOS 8.1 (12B410)

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x00000000000000c0
Triggered by Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   UnityGameApp               0x0000000100a8c834 UnityReportWWWReceivedData (iPhoneWWW.mm:208)
1   UnityGameApp               0x0000000100a8c828 UnityReportWWWReceivedData (iPhoneWWW.mm:207)
2   UnityGameApp               0x000000010005b650 -[UnityWWWConnectionDelegate connection:didReceiveData:] (WWWConnection.mm:155)
3   CFNetwork                         0x0000000183a7dfc8 __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 76
4   CFNetwork                         0x0000000183a7df58 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 204
5   CFNetwork                         0x0000000183a7e0d4 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 56
6   CFNetwork                         0x0000000183a67cd4 _NSURLConnectionDidReceiveData(_CFURLConnection*, __CFData const*, long, void const*) + 76
7   CFNetwork                         0x00000001839503b4 ___ZN27URLConnectionClient_Classic29_delegate_didReceiveDataArrayEv_block_invoke + 232
8   CFNetwork                         0x0000000183a1b698 ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 100
9   CFNetwork                         0x000000018393efa0 RunloopBlockContext::_invoke_block(void const*, void*) + 72
10  CoreFoundation                   0x0000000183ebcbf8 CFArrayApplyFunction + 64
11  CFNetwork                         0x000000018393ee4c RunloopBlockContext::perform() + 132
12  CFNetwork                         0x000000018393ed00 MultiplexerSource::perform() + 308
13  CFNetwork                         0x000000018393eb2c MultiplexerSource::_perform(void*) + 64
14  CoreFoundation                   0x0000000183f920e4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 20
15  CoreFoundation                   0x0000000183f91388 __CFRunLoopDoSources0 + 260
16  CoreFoundation                   0x0000000183f8f438 __CFRunLoopRun + 708
17  CoreFoundation                   0x0000000183ebd1f0 CFRunLoopRunSpecific + 392
18  GraphicsServices                 0x000000018d0275a0 GSEventRunModal + 164
19  UIKit                             0x00000001887ee780 UIApplicationMain + 1484
20  UnityGameApp               0x000000010005a600 main (main.mm:40)
21  libdyld.dylib                     0x0000000195136a04 start + 0

I’ve just hit this as well, not super sure what’s up with this. Unity 5.1.1p3

I’m seeing an identical crash on IL2CPP and Mono2x.

This is not an issue in 5.0.3p2.

Woopie! I’ve resolved the error by adding a “yield return new WaitForEndOfFrame();” at the beginning of my coroutine before my WWW declaration.

       private IEnumerator LoadMaterialTextureCoroutine(string path, Material material)
        {
            yield return new WaitForEndOfFrame();

            WWW textureLoad = new WWW("file://"+path);

            // This is done in favor of yielding on the WWW variable due to Unity throwing a harmless "Coroutine continue failure" error in editor.
            // Bad -> // yield return textureLoad;
            do
            {
                if ((null == textureLoad) || !string.IsNullOrEmpty(textureLoad.error))
                {
                    Debug.LogErrorFormat(this, "Texture Loading Failed!\nPath: {0}\nError: {1}", path, textureLoad.error);

                    yield break;
                }

                yield return new WaitForEndOfFrame();
            }
            while (!textureLoad.isDone);

            if ((null != material) && material && material.HasProperty("_MainTex"))
            {
               material.mainTexture = textureLoad.textureNonReadable;
            }

            this.renderer.materials = new Material[]{material};

            yield break;
        }

It appears calling multiple coroutines with WWW initializations at the beginning triggers this issue; my best guess is that by adding a frame delay it allows Unity to stagger them.

Again, this only showed up in 5.1.1, I was definitely not seeing it in my previous version of 5.0.3p2.

I ran into this crash after updating unity yesterday as well!! This is a pretty severe issue because I am unable to figure out what is causing this crash since everything was working fine before the update. Considering that some of the plugins I am using are DLL’s without the source, if the crash is happening inside that, I can’t even fix it! Can Unity please take a look at this

  • (void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data

{

if(self->_data == nil)

{

size_t capacity = self->_estimatedLength > 0 ? self->_estimatedLength : 1024;

self->_data = [NSMutableDatadataWithCapacity: capacity];

}

[self->_dataappendData:data];

UnityReportWWWReceivedData(self.udata, [self->_datalength], self->_estimatedLength); ---- EXC_BAD_ACCESS

if(self.shouldAbort)

[connection cancel];

}

domination`UnityReportWWWReceivedData:

0x2a159d0 <+0>: push {r4, r7, lr}

0x2a159d4 <+4>: mov r4, r0

0x2a159d8 <+8>: mov r0, r1

0x2a159dc <+12>: vldr d16, [r4, #104]

0x2a159e0 <+16>: mov r1, r2

0x2a159e4 <+20>: add r7, sp, #0x4

0x2a159e8 <+24>: vmov r9, r3, d16

0x2a159ec <+28>: mov r2, r9

0x2a159f0 <+32>: bl 0x2b69c90 ; CalculateEta at WWW.cpp:137

0x2a159f4 <+36>: str r0, [r4, #0x70]

0x2a159f8 <+40>: str r1, [r4, #0x74]

0x2a159fc <+44>: mov r1, #0x0

0x2a15a00 <+48>: ldr r0, [r4]

→ 0x2a15a04 <+52>: ldr r2, [r0, #0x60]

0x2a15a08 <+56>: mov r0, r4

0x2a15a0c <+60>: pop {r4, r7, lr}

0x2a15a10 <+64>: bx r2

same crash here with 5.0.2p4. But for me it’s somewhere in the parse.com dll so there’s not much that I can do about it.

Hi,
same crash for me as well with Unity 5.1.2. It’s happening when closing the “purchase complete”-popup after IAP. It was working with an older version of Unity, though.
Did anyone find a fix for that UnityReportWWWReceivedData crash? Can’t submit the game to Apple like this…
Thank you!

push, help please!

Hi, did you created a bug for this issue? We could try to fix it with a minimal project.

hi ive got the same error, did you find a fix/submit a bug report?

thanks

I also got this error on iOS and found that UnityReportWWWReceivedData() crashed when a UnityEngine.WWW instance had already been Dispos()ed. WWWConnection.mm has the following difference between 5.0.x and 5.1.x, which seems to cause this very timing-related issue.

--- Unity5.0.2p4/Unity.app/Contents/PlaybackEngines/iossupport/Trampoline/Classes/Unity/WWWConnection.mm    2015-06-02 07:07:56.000000000 +0900
+++ Unity5.1.0/Unity.app/Contents/PlaybackEngines/iossupport/Trampoline/Classes/Unity/WWWConnection.mm    2015-06-01 22:26:08.000000000 +0900
@@ -255,7 +255,9 @@
     NSMutableURLRequest* request =
         [UnityWWWConnectionDelegate newRequestForHTTPMethod:@"GET" url:delegate.url headers:(__bridge NSDictionary*)headerDict];
-    delegate.connection = [NSURLConnection connectionWithRequest:request delegate:delegate];
+    dispatch_async(dispatch_get_main_queue(), ^{
+        delegate.connection = [NSURLConnection connectionWithRequest:request delegate:delegate];
+    });
     return (__bridge_retained void*)delegate;
}
@@ -268,7 +270,10 @@
     [request setHTTPBody:[NSData dataWithBytes:data length:length]];
     [request setValue:[NSString stringWithFormat:@"%d", length] forHTTPHeaderField:@"Content-Length"];
-    delegate.connection = [NSURLConnection connectionWithRequest:request delegate:delegate];
+    dispatch_async(dispatch_get_main_queue(), ^{
+        delegate.connection = [NSURLConnection connectionWithRequest:request delegate:delegate];
+    });
+
     return (__bridge_retained void*)delegate;
}

Solution: replace WWWConnection.mm with the old one.

1 Like

Hey, thanks for posting this! But how do you apply this patch? I tried using patch from command line I got the error :
patch: **** malformed patch at line 11: }

The above code shows only the diff of 5.1.0 since 5.0.2p4 and cannot be applied as a patch to fix the issue. Please edit the file manually and replace the following,

    dispatch_async(dispatch_get_main_queue(), ^{
        delegate.connection = [NSURLConnection connectionWithRequest:request delegate:delegate];
    });

with the following,

    delegate.connection = [NSURLConnection connectionWithRequest:request delegate:delegate];

for the two parts described in the diff.

BTW, the latest 5.1.3p1 release seems to have this fix already (though the release note doesn’t say anything) so we should give it a try.

Had that same problem with 5.2.0f3

Same here. I wonder if it crashes with other plugins. It happened often when inapp-purchase was sending/receiving data.

Is there a good alternative solution to WWW please?

Thanks for the tips on this post. For me, game crashes on iOS when using WWW. I was able to move on from the issue following a tip on another post. I added **-fobjc-arc** to the file **WWWConnection.mm** in the Build Phases tab in Xcode.

I can confirm that Tehelee’s fix works.
Adding

yield returnnew WaitForEndOfFrame();

Solved the problem.
I’m using Unity 5.1.3

I am still getting this exception for over 6 months now from Unity 5.x - Unity 5.4.2,
has anyone been able to fix it?

@ntroncos , where are you suggesting to yield a frame?

Same here… I had hoped that 5.4.1 and 5.4.2 would solve the problem. Apparently, still happening. I don’t know if it’s a good thing, but my team can reproduce this really easy on iOS. We just simulate the Very Bad Connection setting via

Settings → Developer → (NETWORK LINK CONDITIONER) Status → (CHOOSE A PROFILE) Very Bad Network

Then toggle on this setting by setting ‘Enable’ to on.

When firing up our game from XCode, we run into this crash. I think it also helps that our game is online-only.

Hi all,
I will be taking a look at this and try to have it resolved an in a patch in the next couple of weeks. If I find a solution that is localized to the WWWConnection.mm I will post a patch here for you to use. Thanks for all of the information you have posted.
Cheers,
Chris

Hi all,
We were able to narrow down the issue and come up with a resolution. Please replace your current WWWConnection.mm file with the one in the attached zip file. Please let me know if you are still running into issues with these changes. These changes will be going into a patch release soon.
Cheers,
Chris

2856883–208908–WWWConnection.mm.zip (4.39 KB)