Search Unity

  1. Unity 2020.1 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] lot of bundle dependencies will surely fail

Discussion in 'Addressables' started by nik_d, Jun 12, 2019.

  1. nik_d

    nik_d

    Joined:
    Apr 27, 2018
    Posts:
    61
    real sample and provement (It's obvious because factor 9176 has 2^3 multiplier so initial bits are pushed out of int(32) in just 11 iterations =)):
    Code (CSharp):
    1.             var deps = new[] {
    2.                 "<WILL-BE-REPLACED>",
    3.                 "startup-shared_assets_assets/fx_data/textures.bundle",
    4.                 "shared_assets_assets/fx_data/materials.bundle",
    5.                 "shaders_assets_all.bundle",
    6.                 "music_assets_music/maptheme6final.bundle",
    7.                 "fx_tex_assets_all.bundle",
    8.                 "shared_assets_assets/textures/ui/campain_act02.bundle",
    9.                 "shared_assets_assets/fx_data/meshes.bundle",
    10.                 "startup-shared_assets_assets/textures/ui/campain_act02.bundle",
    11.                 "startup-shared_assets_assets/textures/ui/campainart.bundle",
    12.                 "startup-shared_assets_assets/fx_data/materials.bundle",
    13.                 "shared_assets_assets/textures/ui/valleyoftreasures.bundle",
    14.                 "startup-shared_assets_assets/fx_data/meshes.bundle",
    15.                 "startup_UnityBuiltInShaders.bundle",
    16.             };
    17.             int ADDRESSABLES_CUSTOM_HASH(string[] deps1)
    18.             {
    19.                 //seed and and factor values taken from https://stackoverflow.com/question/1646807/quick-and-simple-hash-code-combinations
    20.                 int hashCode = 1009;
    21.                 foreach (var dep in deps1)
    22.                     hashCode = hashCode * 9176 + dep.GetHashCode();
    23.                 return hashCode;
    24.             }
    25.             deps[0] = "maps_assets_ref/valley1.bundle";
    26.             var hashPart1 = deps[0].GetHashCode();
    27.             var hashSum1 = ADDRESSABLES_CUSTOM_HASH(deps);          
    28.             deps[0] = "maps_assets_ref/valley3.bundle";
    29.             var hashPart2 = deps[0].GetHashCode();
    30.             var hashSum2 = ADDRESSABLES_CUSTOM_HASH(deps);
    31.             Debug.Log($"HASH: {hashPart1}=>{hashSum1} ??? {hashPart2}=>{hashSum2}");
    workaround: code in ContentCatalogData.cs to replace with:
    Code (CSharp):
    1.  
    2. //create extra entries for dependency sets
    3. var hashSources = new Dictionary<int, string>(); ////>addressables: bugfix: try to detect incorrectly exported dependencies
    4. ........
    5.                 //**addressables - fix: better hash method for a lot of dependencies and additional checker for the same issue in the future
    6.                 //    (9176 has 2^3 multiplier so inital bits are pushed out of int in just 11 iterations)
    7.                
    8.                 ////seed and and factor values taken from https://stackoverflow.com/questions/1646807/quick-and-simple-hash-code-combinations
    9.                 //int hashCode = 1009;
    10.                 //foreach (var dep in entry.Dependencies)
    11.                 //    hashCode = hashCode * 9176 + dep.GetHashCode();
    12.                
    13.                 var hashSource = string.Join(null, entry.Dependencies);
    14.                 var hashCode = hashSource.GetHashCode(); //NEW HASH METHOD: just for the sum of all dependencies
    15.                 if (hashSources.TryGetValue(hashCode, out var previousHashSource)) {
    16.                     if (hashSource != previousHashSource) {
    17.                         throw new Exception($"INCORRECT HASH: the same hash ({hashCode}) for different dependency lists:\nsource 1: {previousHashSource}\nsource 2: {hashSource}");
    18.                     }
    19.                 } else {
    20.                     hashSources.Add(hashCode, hashSource);
    21.                 }
    22.  
     
    dwit_mass_creation and Wawro01 like this.
  2. Wawro01

    Wawro01

    Joined:
    Apr 23, 2014
    Posts:
    39
    Oh, this fixed me a loot of issues. Thanks! EDIT: Maybe changing 9176 (like
    5381) for some prime number would be sufficient.
     
    Last edited: Jun 13, 2019
  3. nik_d

    nik_d

    Joined:
    Apr 27, 2018
    Posts:
    61
    You're right - some prime number can be sufficient, but checker's cost is nothing, comparing to passed/future debug time on the same. =)
     
  4. sophiepeithos

    sophiepeithos

    Joined:
    Sep 10, 2014
    Posts:
    54
    it is the second time hash collision problem been posted, i hope unity will fix it soon
     
  5. Wawro01

    Wawro01

    Joined:
    Apr 23, 2014
    Posts:
    39
    And still not fixed in 1.1.3 ...
     
  6. chanon81

    chanon81

    Joined:
    Oct 6, 2015
    Posts:
    157
    So sad

    I dare not update to latest Addressables right now cause I don't want to waste days working around new bugs in it like last time I updated.
     
  7. sophiepeithos

    sophiepeithos

    Joined:
    Sep 10, 2014
    Posts:
    54
  8. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    1,010
    It's on the list. not in the soon-to-be-released 1.1.8, but probably the release following
     
  9. sophiepeithos

    sophiepeithos

    Joined:
    Sep 10, 2014
    Posts:
    54
    thanks
     
  10. dwit_mass_creation

    dwit_mass_creation

    Joined:
    Jun 18, 2015
    Posts:
    62
    Thanks for workaround. I had problems with this function in Addressables 1.2.2 too.
     
  11. stefankohl

    stefankohl

    Joined:
    May 30, 2014
    Posts:
    52
    When will this be fixed? It still happens in 1.2.4
     
  12. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    1,010
    We have a fix coming into our master branch now. I'm not sure if it'll make the next release, or the next-next. Apologies this has taken so long.
     
    nik_d likes this.
  13. CristianGarciaJ

    CristianGarciaJ

    Joined:
    Apr 13, 2018
    Posts:
    8
    Hi all,

    While we wait for an official fix I made for our team a workaround with a new hash calculation function (working in all the builds we made):

    Code (CSharp):
    1. internal int CalculateCollectedHash(List<object> objects, Dictionary<int, object> hashSources)
    2.         {
    3.             //alphabetical hashing
    4.             List<object> hashSource = objects.OrderBy(_x => _x.GetType().Name).ToList();
    5.  
    6.             //multiplicative hashing
    7.             int seed = 487;
    8.             int modifier = 31;
    9.             int hashCode = hashSource.Aggregate(seed, (current, item) => (current * modifier) + item.GetHashCode());
    10.          
    11.             if (hashSources.TryGetValue(hashCode, out object previousHashSource))
    12.             {
    13.                 List<object> previousHash = previousHashSource as List<object>;
    14.                 if ( hashSource.Count !=  previousHash.Count)
    15.                 {
    16.                     throw new Exception($"INCORRECT HASH: the same hash ({hashCode}) for different dependency lists:\nsource 1: {previousHashSource}\nsource 2: {hashSource}");
    17.                 }
    18.                 for (int i = 0; i < hashSource.Count; ++i)
    19.                 {
    20.                     if (hashSource[i].GetType().Name != previousHash[i].GetType().Name)
    21.                     {
    22.                         throw new Exception($"INCORRECT HASH: the same hash ({hashCode}) for different dependency lists:\nsource 1: {previousHashSource}\nsource 2: {hashSource}");
    23.                     }
    24.                 }
    25.             }
    26.             else
    27.                 hashSources.Add(hashCode, hashSource);
    28.  
    29.             return hashCode;
    30.         }
    Hope this can help :)
     
    Wawro01 and rg_johnokane like this.
unityunity