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

iOS UnityReportWWWFailedWithError and NSURLErrorDomain error -1002

Discussion in 'iOS and tvOS' started by zrrz, Aug 15, 2015.

  1. zrrz

    zrrz

    Joined:
    Nov 14, 2012
    Posts:
    40
    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:
    * 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 fortressfury`UnityReportWWWFailedWithError + 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:eek:nlyActive:]_block_invoke + 80
    frame #3: 0x00000001845aae00 CFNetwork`-[NSURLConnectionInternal _withConnectionAndDelegate:eek:nlyActive:] + 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 CFNetwork`RunloopBlockContext::_invoke_block(void const, void) + 76
    frame #9: 0x00000001849e8aac CoreFoundation`CFArrayApplyFunction + 68
    frame #10: 0x000000018446ba00 CFNetwork`RunloopBlockContext::perform() + 136
    frame #11: 0x000000018446b8b4 CFNetwork`MultiplexerSource::perform() + 312
    frame #12: 0x000000018446b6e0 CFNetwork`MultiplexerSource::_perform(void*) + 68
    frame #13: 0x0000000184abe9ec CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
    frame #14: 0x0000000184abdc90 CoreFoundation`__CFRunLoopDoSources0 + 264
    frame #15: 0x0000000184abbd40 CoreFoundation`__CFRunLoopRun + 712
    frame #16: 0x00000001849e90a4 CoreFoundation`CFRunLoopRunSpecific + 396
    frame #17: 0x000000018db935a4 GraphicsServices`GSEventRunModal + 168
    frame #18: 0x000000018931e3c0 UIKit`UIApplicationMain + 1488
    frame #19: 0x00000001000a47a4 fortressfury`main(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.
     
  2. zrrz

    zrrz

    Joined:
    Nov 14, 2012
    Posts:
    40
    Here is the code that is breaking it.
    Code (CSharp):
    1. private void doLogEvent(string action, string category, string label)
    2.     {
    3.         action = WWW.EscapeURL(action);
    4.  
    5.         if(category.Length > 0) category = "&ec="+WWW.EscapeURL(category);
    6.         if(label.Length > 0) label = "&el="+WWW.EscapeURL(label);
    7.  
    8.         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);
    9.         new WWW(url, Encoding.UTF8.GetBytes(data), headers);
    10.     }
    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?
     
  3. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
    Could you please submit a bug report and post the bug number here?
     
  4. Iamdain

    Iamdain

    Joined:
    Feb 3, 2010
    Posts:
    90
    @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:eek:nlyActive:]_block_invoke + 76
    2 CFNetwork 0x0000000184dfe67c -[NSURLConnectionInternal _withConnectionAndDelegate:eek: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
     
  5. zrrz

    zrrz

    Joined:
    Nov 14, 2012
    Posts:
    40
    @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...constant_group/URL_Loading_System_Error_Codes
     
  6. Iamdain

    Iamdain

    Joined:
    Feb 3, 2010
    Posts:
    90
    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.
     
  7. zrrz

    zrrz

    Joined:
    Nov 14, 2012
    Posts:
    40
    @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.
     
  8. Iamdain

    Iamdain

    Joined:
    Feb 3, 2010
    Posts:
    90
    @zrrz ok thanks for the extra details