Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[Bug][1.6.2] Hash collisions in BuildScriptPackedMode

Discussion in 'Addressables' started by WeltenbauerRenn, Feb 26, 2020.

  1. WeltenbauerRenn

    WeltenbauerRenn

    Joined:
    Jun 20, 2017
    Posts:
    29
    Hello we have been stuck on 1.3.8 for a while because we got errors when building bundles. Today I looked into the problem and found this part of code:

    BuildScriptPackedMode:391
    Code (CSharp):
    1. for (int i = 0; i < bundleInputDefs.Count; i++)
    2. {
    3.     string assetBundleName = bundleInputDefs[i].assetBundleName;
    4.     if (aaContext.bundleToAssetGroup.ContainsKey(assetBundleName))
    5.     {
    6.         int count = 1;
    7.         var newName = assetBundleName;
    8.         while (aaContext.bundleToAssetGroup.ContainsKey(newName) && count < 1000)
    9.             newName = assetBundleName.Replace(".bundle", string.Format("{0}.bundle", count++));
    10.         assetBundleName = newName;
    11.     }
    12.  
    13.     string hashedAssetBundleName = HashingMethods.Calculate(assetBundleName) + ".bundle";
    14.     m_OutputAssetBundleNames.Add(assetBundleName);
    15.     m_AllBundleInputDefs.Add(new AssetBundleBuild
    16.     {
    17.         addressableNames = bundleInputDefs[i].addressableNames,
    18.         assetNames = bundleInputDefs[i].assetNames,
    19.         assetBundleName = hashedAssetBundleName,
    20.         assetBundleVariant = bundleInputDefs[i].assetBundleVariant
    21.     });
    22.     aaContext.bundleToAssetGroup.Add(hashedAssetBundleName, assetGroup.Guid);
    23. }
    I get a key exception on the last add. I think the line
    string hashedAssetBundleName = HashingMethods.Calculate(assetBundleName) + ".bundle";
    is wrong because the whole testing with ContainsKey is on a different string than the one that is added. When removing the line and adding assetBundleName instead, the build run fine.

    Do I miss something?
     
  2. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    872
    Flagging this for the team. Which version of the editor do you happen to be using?
     
  3. WeltenbauerRenn

    WeltenbauerRenn

    Joined:
    Jun 20, 2017
    Posts:
    29
    I'm using 2019.3.2f1 but we had this issue also in older versions like some 2019.2.x
     
  4. DavidUnity3d

    DavidUnity3d

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    467
    This is unfortunate. I'll get a ticket thrown in for this. We've had issues with this in the past but thought we had fixed that up. Apologies for the inconvenience.
     
  5. WeltenbauerRenn

    WeltenbauerRenn

    Joined:
    Jun 20, 2017
    Posts:
    29
    @DavidUnity3d thank you. It was not that bad I could easily "fork" the package into a local one :)
     
  6. WeltenbauerRenn

    WeltenbauerRenn

    Joined:
    Jun 20, 2017
    Posts:
    29
    I have a another 'fix': BuildScriptFastMode:144
    Code (CSharp):
    1. if (string.IsNullOrEmpty(entry.AssetPath))
    2. {
    3.     return $"{assetGroup.name} has an entry with null or empty path. Address: {entry.address}";
    4. }
    5.  
    6. FileAttributes file = File.GetAttributes(entry.AssetPath);
    7. if (file.HasFlag(FileAttributes.Directory))
    8. {
    9.     GatherAssetsForFolder(entry, aaContext);
    10. }
    11. else
    12.     entry.CreateCatalogEntries(aaContext.locations, false, typeof(AssetDatabaseProvider).FullName,
    13.         null, null, aaContext.providerTypes);
    The if prevent path is empty exception when the asset has been removed / deleted.
     
    DavidUnity3d likes this.
unityunity