Ludeon Forums

RimWorld => Mods => Help => Topic started by: Hatti on August 27, 2016, 06:54:03 PM

Title: [A15] Hash collision on game load with mod that adds buildings
Post by: Hatti on August 27, 2016, 06:54:03 PM
Hey all!

i´m trying to add new buildings with a mod. they work super fine on a new game. But after save and load i get hash collision errors for as it looks every thing:

(http://fs5.directupload.net/images/160828/niwh4b65.png)

it only happens after i load up a save game (save is new, nothing is build, nothing is done, just started new game and saved)
the output.log dont have any other informations as the exception message in the call stack.
in A14 it works just fine

also all mountain tiles are flat

(http://fs5.directupload.net/images/160828/mkyuxoqe.png)


any advices how to fix that?
Title: Re: [A15] Hash collision on game load with mod that adds buildings
Post by: RawCode on August 27, 2016, 09:51:54 PM
1) IL spy or any other reflector (there are no "decompilers")
2) Notepad++
3) Use keywords to find place, where check is located

                                    Verse.Log.Error(string.Concat(new object[] { "Hash collision between ", this.<def>__2, " and  ", this.<thingDefsByShortHash>__0[this.<def>__2.shortHash], ": both have short hash ", this.<def>__2.shortHash }));

4) Then, follow keywords to find, how hash is computed for objects

5)
        public static void GiveShortHash(Def def)
        {
            if (def.shortHash != 0)
            {
                Log.Error(def + " already has short hash.");
            }
            else
            {
                ushort item = (ushort) (GenText.StableStringHash(def.defName) % 0xffff);
                int num2 = 0;
                while (takenHashes.Contains(item) || (item == 0))
                {
                    item = (ushort) (item + 1);
                    num2++;
                    if (num2 > 0x3e8)
                    {
                        Log.Message("Short hashes are saturated because there are too many definitions. Compressed saveload will fail.");
                    }
                }
                def.shortHash = item;
                takenHashes.Add(item);
            }
        }


6) You have too many zeros, probably
        public override void PostLoad()
        {
            base.PostLoad();
            ShortHashGiver.GiveShortHash(this);
        }

not executed properly

7) Make sure, that your objects have proper postload code and no hook is injected into given method

8) Check log (it's located inside _data folder) for warnings and errors, probably you have too many objects
Title: Re: [A15] Hash collision on game load with mod that adds buildings
Post by: Hatti on August 27, 2016, 10:44:34 PM
Ok got it. It seems, my ThingDef classes dont had a defName for hash generation.
thanks
Title: Re: [A15] Hash collision on game load with mod that adds buildings
Post by: 1000101 on August 28, 2016, 04:05:29 PM
Also note that changing anything about floors and terrain requires a new game or you will get the "sand bug".
Title: Re: [A15] Hash collision on game load with mod that adds buildings
Post by: RawCode on August 29, 2016, 01:08:18 AM
Quote from: Hatti on August 27, 2016, 10:44:34 PM
Ok got it. It seems, my ThingDef classes dont had a defName for hash generation.
thanks

very good that you managed to solve problem self, you have bright future ahead, keep going.
Title: Re: [A15] Hash collision on game load with mod that adds buildings
Post by: Jaxxa on August 29, 2016, 01:55:47 AM
Thanks for posting the solution that you found.

I was having a similar issue but hadnt had time to look into it. I will try that fix when I get back to my machine.