Vanilla-Expanded / VanillaExpandedFramework

Vanilla Expanded Framework for RimWorld
Other
73 stars 37 forks source link

Fix NRE in RockUtility.PossibleRockTypesFor #45

Closed m00nl1ght-dev closed 1 year ago

m00nl1ght-dev commented 1 year ago

Currently the method RockUtility.PossibleRockTypesFor relies on World.allNaturalRockDefs being initialized. However, there are mods that add a prefix to World.NaturalRockTypesIn to override the result, such as "Configurable Maps" and "World Edit".

In that case, the vanilla code is skipped and World.allNaturalRockDefs is never initialized. This results in an NRE in RockUtility.PossibleRockTypesFor and causes map generation to fail, and the world map UI to freeze.

This PR makes RockUtility.PossibleRockTypesFor more resilient against this kind of mod compatibility issue, by ensuring World.allNaturalRockDefs is initialized before it is used.

Side note: Alpha Biomes started using the affected code in its latest update, and is often used together with the mentioned mods, which is why this issue pops up often in reports now.

Taranchuk commented 1 year ago

Looks good to me

legodude17 commented 1 year ago

My only worry would be compatibility issues if mods patch NaturalRockTypesIn to modify the allNaturalRockDefs list. Not sure how many do, though.

Taranchuk commented 1 year ago

It's only applied when the list is null I think

m00nl1ght-dev commented 1 year ago

Yeah in that case the field is already initialized and this code doesn't change anything.