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. Dismiss Notice

iOS Player crashes when Dispose() is called on WWW instance (Unity 5.3.4f1)

Discussion in 'iOS and tvOS' started by k_2, Apr 21, 2016.

  1. k_2

    k_2

    Joined:
    Feb 17, 2016
    Posts:
    12
    Unity iOS player crashes when Dispose() is called in specific moments of a download (LoadFromCacheOrDownload()). We've noticed that if you have a good wifi and Internet connection then the download progress just grows steadily. During this steady download there are moments of hiccups - download progress seems to pause for a while (from a fraction of second to a few seconds) and if Dispose() is called then - it crashes. Crash logs indicate it's something with threads data synchronization.

    Our game quite frequently needs to cancel asset bundle download so crashes happen from time to time (or pretty frequently if network is fast and you know when to call Dispose(). We've also checked uncached download using new WWW() but it's the same. Due to this issue the WWW class is useless for us and we're now implementing our own download and simple caching system.

    Bug is on issue tracker:
    https://goo.gl/FMuibb

    Any piece of advice on how to "fix" this issue is welcomed.
     
  2. k_2

    k_2

    Joined:
    Feb 17, 2016
    Posts:
    12
    We'll also test UnityWebRequest - maybe it won't crash.
     
  3. k_2

    k_2

    Joined:
    Feb 17, 2016
    Posts:
    12
    We've tried UnityWebRequest but unfortunately it also crashes when Abort() is called right after the download starts. Bug report:
    https://goo.gl/fgJ029
    Additionally Abort() on iOS may produce invalid error value:
    https://goo.gl/KR3xWJ
     
  4. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hey @k_2,
    I have received your bug report and will be looking into this.
    Cheers,
    Chris
     
  5. k_2

    k_2

    Joined:
    Feb 17, 2016
    Posts:
    12
    Great! If you need any additional info please let me know.
     
  6. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    We're seeing something similar to this on 5.3.5p2 right now ( iOS )

    *On 5.3.4p1 we never saw this, in fact 5.3.4p1 was pretty darn stable. 5.3.5x seems to be more unstable.
     
  7. sdf_eee

    sdf_eee

    Joined:
    May 30, 2015
    Posts:
    55
    5.3.5p2 same problem here.
    5.3.5f1 is fine for me.
    This problem occurs only on iOS. Android is fine.

    Code (CSharp):
    1.  
    2.     public static IEnumerator WWW(string url, byte[] value, Action<WWW> onDone)
    3.     {
    4.         var isFinish = false;
    5.  
    6.         while (isFinish == false)
    7.         {
    8.             var www = new WWW(url, value);
    9.  
    10.             yield return WWWInternal(www, (innerWww) =>
    11.             {
    12.                 isFinish = true;
    13.                 onDone(innerWww);
    14.             });
    15.         }
    16.     }
    17.  
    18.     public static IEnumerator WWWInternal(WWW www, Action<WWW> onDone)
    19.     {
    20.         yield return SomeTimeoutProcess(www);
    21.  
    22.         if (www.isDone && www.error == null)
    23.         {
    24.             onDone(www);
    25.         }
    26.         else
    27.         {
    28.             yield return SomeFailedProcess();
    29.         }
    30.      
    31.         // www.Dispose();
    32.     }
    33.  
    If I execute commented www.Dispose(), application always crash.

    here is crash report.
    =================================================================================
    Hardware Model: iPhone7,1
    Code Type: ARM-64 (Native)

    Date/Time: 2016-06-04 17:52:36.36 +0900
    Launch Time: 2016-06-04 17:52:28.28 +0900
    OS Version: iOS 9.3.1 (13E238)
    Report Version: 105

    Exception Type: EXC_CRASH (SIGSEGV)
    Exception Codes: 0x0000000000000000, 0x0000000000000000
    Exception Note: EXC_CORPSE_NOTIFY
    Triggered by Thread: 1

    Filtered syslog:
    None found

    Breadcrumb Trail: (reverse chronological seconds)
    1 GC Framework: startAuthenticationForExistingPrimaryPlayer

    Thread 0 name: Dispatch queue: com.apple.main-thread
    Thread 0:
    0 libsystem_kernel.dylib 0x0000000180d9f7ec __kill + 8
    1 libsystem_platform.dylib 0x0000000180e6594c _sigtramp + 68
    2 rb 0x0000000100e479d8 TransportiPhone::Abort() (TransportiPhone.cpp:28)
    3 rb 0x0000000100e57edc WWW_CUSTOM_DestroyWWW(ScriptingObjectWithIntPtrField<WWW>, unsigned char) (UtilsBindings.gen.cpp:85)
    4 rb 0x000000010015ddc0 U3CWWWInternalU3Ec__Iterator7_MoveNext_m3509145728 (Bulk_Assembly-CSharp_2.cpp:1933)
    5 rb 0x00000001007692d8 SetupCoroutine_InvokeMoveNext_m3556339879 (Bulk_UnityEngine_2.cpp:5489)
    6 rb 0x0000000100a38a88 RuntimeInvoker_Void_t2779279689_Il2CppObject_IntPtr_t(MethodInfo const*, void*, void**) (Il2CppInvokerTable.cpp:2639)
    7 rb 0x0000000101326ba8 il2cpp::vm::Runtime::Invoke(MethodInfo const*, void*, void**, Il2CppException**) (Runtime.cpp:363)
    8 rb 0x0000000100c3be20 ScriptingInvocation::Invoke(ScriptingException**, bool) (ScriptingInvocation.cpp:180)
    9 rb 0x0000000100c2ef90 Coroutine::InvokeMoveNext(ScriptingException**) (Coroutine.cpp:203)
    10 rb 0x0000000100c2ecfc Coroutine::Run() (Coroutine.cpp:228)
    11 rb 0x0000000100c2ed54 Coroutine::Run() (Coroutine.cpp:259)
    12 rb 0x0000000100c2ed54 Coroutine::Run() (Coroutine.cpp:259)
    13 rb 0x0000000100b08fc4 DelayedCallManager::Update(int) (CallDelayed.cpp:178)
    14 rb 0x0000000100becdac PlayerLoop(bool, bool, IHookEvent*) (Player.cpp:1721)
    15 rb 0x0000000100e6b3f4 UnityPlayerLoopImpl(bool) (LibEntryPoint.mm:240)
    16 rb 0x00000001000eabe8 UnityRepaint (UnityAppController+Rendering.mm:238)
    17 rb 0x00000001000fb4f0 -[UnityAppController(ViewHandling) showGameUI] (UnityAppController+ViewHandling.mm:212)
    18 rb 0x00000001000f8090 -[UnityAppController startUnity (UnityAppController.mm:126)
    19 Foundation 0x0000000181bce628 __NSFireDelayedPerform + 428
    20 CoreFoundation 0x00000001811bd81c __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 28
    21 CoreFoundation 0x00000001811bd4c0 __CFRunLoopDoTimer + 884
    22 CoreFoundation 0x00000001811babd4 __CFRunLoopRun + 1520
    23 CoreFoundation 0x00000001810e4d10 CFRunLoopRunSpecific + 384
    24 GraphicsServices 0x00000001829cc088 GSEventRunModal + 180
    25 UIKit 0x00000001863b9f70 UIApplicationMain + 204
    26 rb 0x00000001000e496c main (main.mm:32)
    27 libdyld.dylib 0x0000000180c828b8 start + 4

    Thread 1 name: Dispatch queue: com.apple.gamecenter.GKDaemonProxy
    Thread 1 Crashed:
    0 libsystem_kernel.dylib 0x0000000180d85014 semaphore_wait_trap + 8
    1 libdispatch.dylib 0x0000000180c628c4 _dispatch_group_wait_slow + 260
    2 GameCenterFoundation 0x000000018f2f7a6c __36-[GKServiceProxy buildServiceLookup]_block_invoke + 752
    3 libdispatch.dylib 0x0000000180c514bc _dispatch_call_block_and_release + 24
    4 libdispatch.dylib 0x0000000180c5147c _dispatch_client_callout + 16
    5 libdispatch.dylib 0x0000000180c5d4c0 _dispatch_queue_drain + 864
    6 libdispatch.dylib 0x0000000180c54f80 _dispatch_queue_invoke + 464
    7 libdispatch.dylib 0x0000000180c5147c _dispatch_client_callout + 16
    8 libdispatch.dylib 0x0000000180c5f914 _dispatch_root_queue_drain + 2140
    9 libdispatch.dylib 0x0000000180c5f0b0 _dispatch_worker_thread3 + 112
    10 libsystem_pthread.dylib 0x0000000180e69470 _pthread_wqthread + 1092
    11 libsystem_pthread.dylib 0x0000000180e69020 start_wqthread + 4
     
    Last edited: Jun 4, 2016
  8. DanjelRicci

    DanjelRicci

    Joined:
    Mar 8, 2010
    Posts:
    304
    I can confirm too that WWW.Dispose() crashes on iOS with Unity 5.3.5p2 but not with 5.3.5.p1.
     
  9. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hey @sdf_eee,
    Thanks for the repro script. Can you also file a bug report and post the number here. I will look into fixing this today.
    Cheers,
    Chris
     
  10. sdf_eee

    sdf_eee

    Joined:
    May 30, 2015
    Posts:
    55
  11. mkg2w

    mkg2w

    Joined:
    Aug 19, 2013
    Posts:
    49
    We have the same error when calling WWW.Dispose to terminate a ongoing download of an AssetBundle.

    The crash typically occurs only after 20-30% of the download has completed (in our case after downloading 6-9MB).

    Calling WWW.Dispose shortly after the download begins does not cause the app to crash.

    Code works fine in Editor. Bug is only in iOS.

    Error occurs on both Unity 5.3.5p1 and p2.
     
  12. games2win

    games2win

    Joined:
    Nov 20, 2015
    Posts:
    2
    A correction to earlier post : the pattern for crashing seems to be the rate at which the download is progressing; seems to be some sort of race condition on the file handle.
     
  13. sdf_eee

    sdf_eee

    Joined:
    May 30, 2015
    Posts:
    55
    Yes. my Crash would occur during the download of AssetBundle.
     
  14. k_2

    k_2

    Joined:
    Feb 17, 2016
    Posts:
    12
    Just a theory but this crash might happen during streamed data decompression - while decompression thread decompresses stream data, the Dispose() is called on the main thread which invalidates streamed data pointers (or data itself) causing the compression thread to read/write invalid data (pointers). It may be the case that default unity behavior which is recompressing LZMA into LZ4 on the fly causes this issue. Unfortunately I don't have time to test this but recompression can be disabled using Caching.compressionEnabled (default is true). This will result in longer asset budles loading time. Docs on asset bundle compression: http://docs.unity3d.com/Manual/AssetBundleCompression.html
     
  15. k_2

    k_2

    Joined:
    Feb 17, 2016
    Posts:
    12
    Also you can avoid decompression while using LZ4 when building the asset bundles - the recompression shouldn't take place but you'll get larger files to download.
     
  16. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hello all,
    We have discovered and resolved the issue. Thanks for bringing it to light and for your patience. I will update this thread once I know which patch release this fix will be going into.
    Cheers,
    Chris
     
    KB73 and sdf_eee like this.
  17. capyvara

    capyvara

    Joined:
    Mar 11, 2010
    Posts:
    80
    Do you know if it's fixed on 5.3.5p3? Basically it is a breaking change for us.
     
  18. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hi all,
    The fix will be going into 5.3.5p4.

    Sorry for the regression. Some details: There is a test in place for calling dispose on a WWW object while it's in flight. It seems that the crash doesn't happen immediately on some devices and it's possible that our testing suite finished before the crash occured. I am investigating why this is the case and am hoping to fix it.
    Cheers,
    Chris
     
    sdf_eee and dcheglakov like this.
  19. adamt

    adamt

    Joined:
    Apr 1, 2014
    Posts:
    116
    I'm not sure if this is related, but I'm actually getting the issue (or a similar one) in 5.3.5p4, but not in previous versions (5.3.5p3 and 5.3.5p2, specifically). The only difference on my end is that I'm using UnityWebRequest, not WWW. I've created a bug report (807366). Are these two classes not using the same underlying codebase?
     
  20. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hey @adamt,
    Thanks for your bug report. I will be looking into this. For the iOS implementation there are some common classes between WWW and WebRequest.
    Cheers,
    Chris
     
  21. games2win

    games2win

    Joined:
    Nov 20, 2015
    Posts:
    2
    In 5.3.5p2, we used WebRequest.Dispose to get around the crash on Dispose. However, there's an issue with detecting network failures.
    We observed that if the network is disconnected while WebRequest is downloading content, it falsely reports the download is a success. We have no such problems with WWW.
     
  22. beQr86

    beQr86

    Joined:
    Jul 2, 2015
    Posts:
    21
    Last edited: Jun 21, 2016
    pixelPhil likes this.
  23. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hey @beQr86,
    I see in that forum post that you saw this happen immediately after CompleteContent. This may be unrelated to this thread so I will reply to you there.
    Cheers,
    Chris
     
    pixelPhil likes this.
  24. beQr86

    beQr86

    Joined:
    Jul 2, 2015
    Posts:
    21
    @christophergoy hi ! Sorry for pinging you out but we saw that a new Unity patch (5.3.5p5) got just released, does't it fix the networking ios crash issues ? (its not really pointed out in the patch notes).

    Thanks
     
  25. christophergoy

    christophergoy

    Unity Technologies

    Joined:
    Sep 16, 2015
    Posts:
    735
    hey @beQr86,
    I believe that the fix for the issue on this thread was released in 5.3.5p4. There were no fixes related to your CompleteContent crash mentioned in the other thread. I am looking into that now. If you could, please reply to me on that thread for that issue.
    Cheers,
    Chris
     
  26. skullthug

    skullthug

    Joined:
    Oct 16, 2011
    Posts:
    200
    So, I'm running Unity 5.6.2f and am definitely 100% of the time getting this crash to occur on iOS when calling Dispose() inside of a LoadFromCacheOrDownload call that is being cancelled.
     
  27. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,624
    Can you show the script code where WWW is used?
     
  28. skullthug

    skullthug

    Joined:
    Oct 16, 2011
    Posts:
    200
    I may have spoke prematurely, technically at least. After doing some more testing and removing Dispose() I find LoadFromCacheOrDownload still crashes on iOS if the cancelled state occurs.

    Code (CSharp):
    1. while (!Caching.ready)
    2. yield return null;
    3.         // Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache
    4.         using(WWW www = WWW.LoadFromCacheOrDownload (URL, ver))
    5.         {
    6.             float lastProgressMade=www.progress;
    7.             float lastProgressTimeStamp=Time.time;
    8.             Debug.Log("Loading from: " + URL);
    9.             while( !www.isDone && !cancelled && !timedOut )
    10.             {
    11.                 if (Time.time > startTime+timeBeforeLoadDisplay && !ModelManager.instance.BundleDownloadPanel.activeSelf)
    12.                 {
    13.                     ModelManager.instance.BundleDownloadPanel.SetActive(true);
    14.                 }
    15.  
    16.                 //timeout logic
    17.                 if (www.progress != lastProgressMade)
    18.                 {
    19.                     lastProgressMade = www.progress;
    20.                     lastProgressTimeStamp = Time.time;
    21.                     #if DEBUG
    22.                     Debug.Log ("Bundle Download progress: " + www.progress);
    23.                     #endif
    24.                     ModelManager.instance.BundleProgressBar.value = www.progress;
    25.                 }
    26.                 else
    27.                 {
    28.                     if (Time.time > lastProgressTimeStamp + timeOutTime)    
    29.                         timedOut=true;
    30.                 }
    31.  
    32.                 yield return null;
    33.             }
    34.  
    35.             if (cancelled)
    36.             {
    37.                 ModelManager.instance.BundleDownloadPanel.SetActive(false);            
    38.                 www.Dispose();
    39.                 Debug.Log ("Cancelled");
    40.                 yield return errorCancelled;
    41.                 yield break;
    42.             }
    43.  
    44.             if (timedOut)
    45.             {
    46.                 ModelManager.instance.BundleDownloadPanel.SetActive(false);            
    47.                 www.Dispose();            
    48.                 Debug.Log ("Timed out");
    49.                 RecordAnal.RecordEvent(assetName + " bundle download timed out");
    50.                 yield return errorTimedOut;
    51.                 yield break;
    52.             }
    53.  
    54.             yield return www;
    55.             if (!string.IsNullOrEmpty(www.error))
    56.                 //throw new Exception("WWW download had an error:" + www.error);
    57.             {
    58.                 Debug.LogError("WWW download had an error:" + www.error);
    59.                 RecordAnal.RecordEvent(assetName + " bundle download had an error: " + www.error);
    60.                 yield return null;
    61.             }
    62.             else
    63.             {
    64.                 if (assetName!="")
    65.                 {
    66.                     AssetBundle bundle = www.assetBundle;
    67.                     //yield return bundle.mainAsset;
    68.                     yield return bundle.LoadAsset(assetName);
    69.                     // Unload the AssetBundles compressed contents to conserve memory
    70.                     bundle.Unload(false);
    71.                 }
    72.  
    73.     //            if (AssetName == "")
    74.     //                Instantiate(bundle.mainAsset);
    75.     //            else
    76.     //                Instantiate(bundle.LoadAsset(AssetName));
    77.  
    78.             }
    79.         } // memory is freed from the web stream (www.Dispose() gets called implicitly)
    80.         ModelManager.instance.BundleDownloadPanel.SetActive(false);
    81.     }
     
  29. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,624
    I think it doesn't matter if you dispose or just throw away WWW object. It gets GC-ed in the later case and sounds like aborting download doesn't work.
    One thing worth to try is downloading asset bundle as file and then load it. That would at least clarify where the issue is.