[A16] Short Hash Collisions still occur with grandchildren of Def

Started by Love, December 22, 2016, 03:04:24 AM

Previous topic - Next topic

Love

When inheriting from, as an example, ThingDef, short hash collisions can occur because the game's hash maker only considers children of Def as worthy of hash separation (but not grandchildren).

This means that mods that inherit from a child of Def can accidentally add items that conflict with other mods (or even core game objects) when the short hash is generated on save load.


This has been reported before with Tynan slating a fix for A16, as seen here:

Quote from: Tynan on October 02, 2016, 08:55:11 PM
In other news, I already totally refactored the hash giving to solve the ambiguities with Def subclassing so this sort of issue should be gone, theoretically, in A16.

Unfortunately, it seems that the issue still persists, and needs to be looked at once more.

notfood

I can reproduce it consistenly and very easily. The following will produce a hash collision. I got two hits against Core hashes in my seeds mod.
"Seedwatermelon" clashes with "EggTortoiseFertilized"
"SeedGoldLeaf" clashes with "Battery"

namespace test
{
public class MySpecialSnowFlakeDef : Verse.ThingDef
{
public override void PostLoad ()
{
base.PostLoad();

Log.Message("I'm special!");
}
}
}


<?xml version="1.0"?>
<Defs>
  <ThingDef Name="ResourceBase" Abstract="True">
    <thingClass>ThingWithComps</thingClass>
    <category>Item</category>
    <resourceReadoutPriority>Middle</resourceReadoutPriority>
    <useHitPoints>true</useHitPoints>
    <selectable>true</selectable>
    <altitudeLayer>Item</altitudeLayer>
    <stackLimit>75</stackLimit>
    <statBases>
      <Beauty>-7</Beauty>
    </statBases>
    <comps>
      <li Class="CompProperties_Forbiddable"/>
    </comps>
    <alwaysHaulable>true</alwaysHaulable>
    <drawGUIOverlay>true</drawGUIOverlay>
    <rotatable>false</rotatable>
    <pathCost>15</pathCost>
  </ThingDef>
 
  <test.MySpecialSnowFlakeDef ParentName="ResourceBase">
    <defName>Seedwatermelon</defName>
    <label>special snowflake</label>
    <description>This is a special snowflake.</description>
    <graphicData>
      <texPath>SpecialSnowflake</texPath>
      <graphicClass>Graphic_Single</graphicClass>
    </graphicData>
    <statBases>
      <MaxHitPoints>50</MaxHitPoints>
      <Flammability>1.0</Flammability>
      <DeteriorationRate>1</DeteriorationRate>
      <MarketValue>100</MarketValue>
      <SellPriceFactor>0.01</SellPriceFactor>
    </statBases>
    <soundInteract>Grain_Drop</soundInteract>
    <soundDrop>Grain_Drop</soundDrop>
    <thingCategories>
      <li>FoodRaw</li>
    </thingCategories>
  </test.MySpecialSnowFlakeDef>
</Defs>


Mod is attached, to reproduce, just spawn the SpecialSnowflake, save, restart RimWorld, then load.


[attachment deleted by admin due to age]

Love

Quick addendum, the error that specifically comes up with notfood's example is

Hash collision between Seedwatermelon and  EggTortoiseFertilized: both have short hash 64647