Search Unity

Problem when the ios build download AssetBundle via WWW.LoadFromCacheOrDownload

Discussion in 'iOS and tvOS' started by seno, Nov 27, 2014.

  1. seno

    seno

    Joined:
    Aug 5, 2010
    Posts:
    17
    Hello.

    I recently experience unexpected black out for running the ios build. The situation of this issue is mostly
    identical with following post.

    http://answers.unity3d.com/questions/486445/problem-when-loading-many-assetbundles-use-www-cac.html

    It used to work fine before and works fine in Android, but it just starts happening in iOS. First, I presents the partial code.

    --------Code calling WWW.LoadFromCahceOrDownload---------------------------

    while (!Caching.ready)
    yield return new WaitForSeconds(0.01f);

    WWW downloadWWW =
    WWW.LoadFromCacheOrDownload(myNeedToDownloadList[index].DownloadURL
    #if !UNITY_EDITOR // Using nocache in UnityEditor causes unexpected termination of UnityEditor
    + "?nocache=" + SystemConfig.GetCurServerTime()
    #endif
    , myNeedToDownloadList[index].Version);

    myPassedTimeForOneDownload = 0f;
    // Waiting to finish download file
    while (!downloadWWW.isDone)
    {
    myPassedTimeForOneDownload += Time.deltaTime;

    // Signal of the internet disconnected
    if (myPassedTimeForOneDownload < 0f)
    {
    break;
    }
    // Possible WWW timeout. Check the internet connection
    else if (myPassedTimeForOneDownload > SystemConfig.WWW_TIMEOUT)
    {
    // TODO: Replace to the generic network connectibility checking solution
    // Calling to Server to check internet connectibility
    ClientNetwork.CHECK_VERSION(this);
    myPassedTimeForOneDownload = 0f;
    }

    yield return new WaitForSeconds(SystemConfig.TIME_WAIT_INTERVAL);
    }
    ---------------------------------------------------------

    -------------------- XCode Logs from iPhone 4 --------------------
    // From the almost end of download assetbundle files(total number is around 250 files)
    starting www download: http://XXX.XXX.XXX/AssetBundles_iPhone/zones/DEVIL_02.nta?nocache=1417069983

    Failed to open file at path: /var/mobile/Applications/4FEFF803-086C-4A67-BA63-5ED15B13A8C6/Library/UnityCache/Temp/abc7d305857e2484d85215384329ebfd/CAB-88261ce3fdef04a94b1c84d8a22be2a4

    (Filename: Line: 294)

    Failed to open file at path: /var/mobile/Applications/4FEFF803-086C-4A67-BA63-5ED15B13A8C6/Library/UnityCache/Temp/abc7d305857e2484d85215384329ebfd/CAB-88261ce3fdef04a94b1c84d8a22be2a4

    ......................
    // After finishing to download all assetbundle files with previous error messages
    Could not open file /var/mobile/Applications/4FEFF803-086C-4A67-BA63-5ED15B13A8C6/puzzlehench.app/Data/level3 for read


    (Filename: Line: 136)


    Could not open file /var/mobile/Applications/4FEFF803-086C-4A67-BA63-5ED15B13A8C6/puzzlehench.app/Data/unity default resources for read


    (Filename: Line: 136)


    Could not open file /var/mobile/Applications/4FEFF803-086C-4A67-BA63-5ED15B13A8C6/puzzlehench.app/Data/unity default resources for read


    (Filename: Line: 136)


    Could not open file /var/mobile/Applications/4FEFF803-086C-4A67-BA63-5ED15B13A8C6/puzzlehench.app/Data/sharedassets3.assets for read

    // Then, everything goes to blackout, but I can hear playing BGM.
    -------------------------------------------------------------

    For more detail,

    XCode version 6.1.1
    Unity3D version 4.5.5
    Build as strip by code

    Finally, it's not crash, but it's not presenting any visuals.

    Any clues will be very appreciate.


    Thanks

    Danny
     
  2. ricardo_arango

    ricardo_arango

    Unity Technologies

    Joined:
    Jun 18, 2009
    Posts:
    64
    You are probably opening a lot of files and not closing them and that will hit a limit. It's not possible to open an infinite amount of files. The OS will limit the number of files that you can open at the same time.

    In your code, after you have downloaded the file, you should then load the assetbundle with .assetBundle, load the assets you need from it using AssetBundle.Load() and then unload the ones that you don't need with AssetBundle.Unload (false) and finally dispose of the WWW object with WWW.Dispose().
     
    Graham-Dunnett likes this.
  3. seno

    seno

    Joined:
    Aug 5, 2010
    Posts:
    17
    Thanks ricardo_arango for reply.

    I am sure that I call WWW.Dispose() for every WWW instances those I created.
    However, my download system has option that keeps assetbundle into a List, so can load later.
    And I enabled the option for the time when I encountered the error.

    So, about 250 assetbundles are stored in the List and not unloaded.
    Do you think this is the case why I encountered the error?

    Danny
     
  4. Alden-R

    Alden-R

    Joined:
    Aug 19, 2014
    Posts:
    10
    seno, that's likely what you're hitting. You get a total of 256 file handles I believe. Holding onto an asset bundle takes 2. You need to reduce the number of asset bundles you have loaded at once.
     
  5. seno

    seno

    Joined:
    Aug 5, 2010
    Posts:
    17
    Hello, Alden.

    First of all, thanks for confirming possible problem.

    But, I double checked my download system and it turned out, it didn't unload only 5 ~ 10 assetbundles those
    contains about 1024 x 1024 size icon atlases.

    I am currently applying new way to handle download by request of my colleagues to minimize memory usage by
    not to hold downloaded assetbundle and I will report more about this. later.

    Thanks