[A17.1546] Hash collisions in RimWorld.CostListCalculator.RequestHash

Started by Fluffy (l2032), May 29, 2017, 04:52:57 PM

Previous topic - Next topic

Fluffy (l2032)

Problem description;
RequestHash uses the short hash of the buildableDef, optionally adjusted with the hash of the stuffdef, to cache the production costs of a buildableDef/stuffDef combinations.

There's two ways collisions can slip in here. First, buildableDefs can be either TerrainDef or ThingDef, each has their own hashtable - so the sets of hashes may overlap. Second, by offsetting with the stuff used, we're deviating from the unique hashes enforced while originally handing out hashes, again introducing a risk of collisions.

Reproduction;
I ran into this issue with the following defs;
MultiAnalyzer
Jade_StuffedStoneRoughTiles

You can test by adding my StuffedFloors mod (which requires ArchitectSense), and trying to build the jade rough stone tiles and the multianalyzer. Whichever you look at first will be the cost for the other as well.


[attachment deleted by admin due to age]

ison

Fixed, thanks.

QuoteThere's two ways collisions can slip in here. First, buildableDefs can be either TerrainDef or ThingDef, each has their own hashtable - so the sets of hashes may overlap.

You're right.

QuoteSecond, by offsetting with the stuff used, we're deviating from the unique hashes enforced while originally handing out hashes, again introducing a risk of collisions.

We're not because we're only modifying the upper bits.

Thanks for reporting.