Search Unity

[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:
    35
    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.  
     
    Wawro01 likes this.
  2. Wawro01

    Wawro01

    Joined:
    Apr 23, 2014
    Posts:
    28
    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:
    35
    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:
    24
    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:
    28
    And still not fixed in 1.1.3 ...
     
  6. chanon81

    chanon81

    Joined:
    Oct 6, 2015
    Posts:
    88
    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:
    24
  8. unity_bill

    unity_bill

    Unity Technologies

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