[A17] Error if butchering a humanlike corpse with a pawn without a 'mood' need

Started by DoctorVanGogh, June 25, 2017, 06:13:18 AM

Previous topic - Next topic

DoctorVanGogh

If you butcher a humanlike corpse with a pawn that does not have a 'mood' need (Example: Alaestor's Robots++ 'Kitchen Bot') the butcher job will throw an error, not complete (and restart again, to just cause another error again & again & again....)


System.NullReferenceException: Object reference not set to an instance of an object

(Triggered inside Corpse.<ButcherProducts>c__Iterator22C.MoveNext())

Since I'm currently writing a mod that mucks around in the butchering jobs, and thus am knee deep in (code) guts anyway I took a look and found the cause of the bug:

The Corpse.ButcherProducts Iterator does not check if the butchering pawn does actually have a non-null 'mood' property before trying to add a 'ThoughtDefOf.ButcheredHumanlikeCorpse' thought. Thus this instruction blows, and the method never completes.
The code does check all pawns who should get a 'ThoughtDefOf.KnowButcheredHumanlikeCorpse' debuff ;)

I've actually put together a bugfix mod that includes code which correctly catches this condition (needs a C# 6.0 capable compiler, otherwise you'll have to manually unfold all those '?.' null propagations).
Appreciate my mods? Buy me a coffee