iOS UnityReportWWWFailedWithError and NSURLErrorDomain error -1002

I’m getting a crash on iOS only with a EXC_BAD_ACCESS in WWWConnection.mm UnityReportWWWFailedWithError (Line 163). Error code is NSURLErrorDomain -1002.

bt all in thread 1:
Error

  • thread #1: tid = 0x23bf77, 0x0000000101467078 fortressfury`UnityReportWWWFailedWithError + 36 at iPhoneWWW.mm:189, queue = ‘com.apple.main-thread’, stop reason = EXC_BAD_ACCESS (code=1, address=0x10000000000000c0)
  • frame #0: 0x0000000101467078 fortressfuryUnityReportWWWFailedWithError + 36 at iPhoneWWW.mm:189 frame #1: 0x00000001000a62ec fortressfury-[UnityWWWConnectionDelegate connection:didFailWithError:](self=0x00000001706ae940, _cmd=0x0000000189af0dbc, connection=0x0000000170219800, error=0x000000017445c830) + 188 at WWWConnection.mm:163
    frame #2: 0x00000001845aae70 CFNetwork__65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 80 frame #3: 0x00000001845aae00 CFNetwork-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 208
    frame #4: 0x00000001845aafcc CFNetwork-[NSURLConnectionInternal _withConnectionAndDelegate:] + 60 frame #5: 0x0000000184594d9c CFNetwork_NSURLConnectionDidFail(_CFURLConnection, __CFError, void const*) + 88
    frame #6: 0x000000018454a410 CFNetwork___ZN27URLConnectionClient_Classic17_delegate_didFailEP9__CFErrorU13block_pointerFvvE_block_invoke + 120 frame #7: 0x0000000184548540 CFNetwork___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 104
    frame #8: 0x000000018446bb54 CFNetworkRunloopBlockContext::_invoke_block(void const, void) + 76 frame #9: 0x00000001849e8aac CoreFoundationCFArrayApplyFunction + 68
    frame #10: 0x000000018446ba00 CFNetworkRunloopBlockContext::perform() + 136 frame #11: 0x000000018446b8b4 CFNetworkMultiplexerSource::perform() + 312
    frame #12: 0x000000018446b6e0 CFNetworkMultiplexerSource::_perform(void*) + 68 frame #13: 0x0000000184abe9ec CoreFoundationCFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 24
    frame #14: 0x0000000184abdc90 CoreFoundation__CFRunLoopDoSources0 + 264 frame #15: 0x0000000184abbd40 CoreFoundation__CFRunLoopRun + 712
    frame #16: 0x00000001849e90a4 CoreFoundationCFRunLoopRunSpecific + 396 frame #17: 0x000000018db935a4 GraphicsServicesGSEventRunModal + 168
    frame #18: 0x000000018931e3c0 UIKitUIApplicationMain + 1488 frame #19: 0x00000001000a47a4 fortressfurymain(argc=1, argv=0x000000016fd5f9d0) + 212 at main.mm:32
    frame #20: 0x000000019587ea08 libdyld.dylib`start + 4

It seems to be an iOS issue and not me messing up somewhere, but maybe not? Any help would be appreciated.

I’m on Unity 5.1.2f1, XCode 6.4, and targeting iOS 7.0.
Using IL2CPP, .NET 2.0 subset, and stripping level set to Strip Byte code (even though I think stripping is ignored on IL2CPP?)

I have put debug logs EVERYWHERE in my code and have yet to find the moment right before it crashes. Maybe that will lead to more info.

Here is the code that is breaking it.

private void doLogEvent(string action, string category, string label)
    {
        action = WWW.EscapeURL(action);

        if(category.Length > 0) category = "&ec="+WWW.EscapeURL(category);
        if(label.Length > 0) label = "&el="+WWW.EscapeURL(label);

        string data = "v=1&ul="+lang+"&t=event&sr="+screenRes+"&an="+WWW.EscapeURL(appName)+"&tid="+propertyID+"&aid="+bundleID+"&cid="+WWW.EscapeURL(clientID)+"&av="+appVersion+"&ea="+action+category+label+"&qt=2500"+agent+"&z="+(int)(UnityEngine.Random.value * 10000000f);
        new WWW(url, Encoding.UTF8.GetBytes(data), headers);
    }

I don’t understand why it’s breaking it, and why the error message and stack that pop up aren’t clear. Anyone have any insight?

Could you please submit a bug report and post the bug number here?

@zrrz did you ever figure this out or find any further clues? Any chance you still have a stack trace you could share?

Not many threads about WWW failures but I wonder if it’s related to crash we’re finding logged from some live devices… Finding it hard to tell form our trace below if the failure was caused by an attempt to access the callback delegate or if the connection itself failed.

@povilas I know it’s not much to go on but do you think these are related problems? Do you think they might be Unity or native in origin? Also what is iPhoneWWW.mm, is that part of compiled Unity code? I can’t find it anywhere and only two references to it on Google. Thanks…

0 ***** 0x0000000101201d38 UnityReportWWWFailedWithError (iPhoneWWW.mm:197)
1 CFNetwork 0x0000000184dfe6ec __65-[NSURLConnectionInternal _withConnectionAndDelegate:hushed:nlyActive:]_block_invoke + 76
2 CFNetwork 0x0000000184dfe67c -[NSURLConnectionInternal _withConnectionAndDelegate:hushed:nlyActive:] + 196
3 CFNetwork 0x0000000184dfe83c -[NSURLConnectionInternal _withConnectionAndDelegate:] + 52
4 CFNetwork 0x0000000184dd2398 _NSURLConnectionDidFail(_CFURLConnection*, __CFError*, void const*) + 76
5 CFNetwork 0x0000000184d5adfc ___ZN27URLConnectionClient_Classic17_delegate_didFailEP9__CFErrorU13block_pointerFvvE_block_invoke + 112
6 CFNetwork 0x0000000184d58e7c ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 104
7 libdispatch.dylib 0x00000001840e95f0 _dispatch_client_callout + 12
8 libdispatch.dylib 0x00000001840f292c _dispatch_block_invoke + 536
9 CFNetwork 0x0000000184c57a88 RunloopBlockContext::_invoke_block(void const*, void*) + 32
10 CoreFoundation 0x00000001845790ac CFArrayApplyFunction + 64
11 CFNetwork 0x0000000184c5796c RunloopBlockContext::perform() + 132
12 CFNetwork 0x0000000184c5782c MultiplexerSource::perform() + 308
13 CFNetwork 0x0000000184c57658 MultiplexerSource::_perform(void*) + 64
14 CoreFoundation 0x000000018464cefc CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 20
15 CoreFoundation 0x000000018464c990 __CFRunLoopDoSources0 + 536
16 CoreFoundation 0x000000018464a690 __CFRunLoopRun + 720
17 CoreFoundation 0x0000000184579680 CFRunLoopRunSpecific + 380
18 GraphicsServices 0x0000000185a88088 GSEventRunModal + 176
19 UIKit 0x00000001893f0d90 UIApplicationMain + 200
20 ***** 0x00000001000537b4 main (main.mm:37)
21 ??? 0x000000018411a8b8 0x0 + 0

@Iamdain Sorry, I never figured out the reason. This was a function in a custom made google analytics class. I just removed it as it was unnecessary to the game.

Absolutely don’t take my word for it 100% but I think I remember seeing a fix for something similar to this a few months later. Could try upgrading Unity and seeing how that goes.

If not, then there’s also a way to see the error code of UnityReportWWWFailedWithError. Mine was a NSURLErrorDomain -1002. I think I found it by using a debug breakpoint. Here is the list of what the error codes mean if you can find it: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/index.html#//apple_ref/doc/constant_group/URL_Loading_System_Error_Codes

Thanks very much for that @zrrz , I’ll look into those error codes and see if we can expose that number.

We just tried a number of methods of decompilation on the .a library containing UnityReportWWWFailedWithError and it seems that MAYBE the function was being passed a failed connection message with some data that was in improper form and subsequently caused an exception.

Still at a loss on how we’ll track down the actual triggering source of the error, needle in a haystack as the crash happens on app load when about 7 different plugins init and it’s rare (but consistent for users that experience it) so we haven’t figured out how to reproduce it here.

Can I ask how you managed to isolate google analytics as the cause? Was it easy to reproduce in your case?

Also considering commenting out / blocking / overriding the UnityReportWWWFailedWithError method if we can find a way to do that as it’s a reporting function we don’t currently use.

@Iamdain Unfortunately, I was only able to track it down by debug logging, breakpointing, and going step by step until I found the exact function that broke it, which is what I put above.

@zrrz ok thanks for the extra details