catgirlfighter/RimWorld_CommonSense

ToxicFallout IndexOutOfRangeException for pawns in trade ships

bonesbro opened this issue · 2 comments

This is fairly niche, and the exception is mostly in vanilla code, but it results in error spam and I think the Need_NeedInterval_CommonSensePatch patch can be updated to avoid it.

  1. A trade ship passes by containing pawns
  2. This error spam starts:
Exception while recalculating ToxicFallout thought state for pawn Gorilla: System.IndexOutOfRangeException: Index was outside the bounds of the array.
  at Verse.RoofGrid.Roofed (Verse.IntVec3 c) [0x00017] in <2ac9ff1464ea49a284d37555c9c1f6ec>:0 
  at Verse.GridsUtility.Roofed (Verse.IntVec3 c, Verse.Map map) [0x00000] in <2ac9ff1464ea49a284d37555c9c1f6ec>:0 
  at RimWorld.ThoughtWorker_ToxicFallout.CurrentStateInternal (Verse.Pawn p) [0x00014] in <2ac9ff1464ea49a284d37555c9c1f6ec>:0 
  at RimWorld.ThoughtWorker.CurrentState (Verse.Pawn p) [0x00010] in <2ac9ff1464ea49a284d37555c9c1f6ec>:0 
  at (wrapper dynamic-method) RimWorld.SituationalThoughtHandler.RimWorld.SituationalThoughtHandler.TryCreateThought_Patch1(RimWorld.SituationalThoughtHandler,RimWorld.ThoughtDef)
UnityEngine.StackTraceUtility:ExtractStackTrace ()
(wrapper dynamic-method) Verse.Log:Verse.Log.Error_Patch1 (string)
(wrapper dynamic-method) RimWorld.SituationalThoughtHandler:RimWorld.SituationalThoughtHandler.TryCreateThought_Patch1 (RimWorld.SituationalThoughtHandler,RimWorld.ThoughtDef)
RimWorld.SituationalThoughtHandler:CheckRecalculateMoodThoughts ()
RimWorld.SituationalThoughtHandler:AppendMoodThoughts (System.Collections.Generic.List`1<RimWorld.Thought>)
RimWorld.ThoughtHandler:GetAllMoodThoughts (System.Collections.Generic.List`1<RimWorld.Thought>)
RimWorld.ThoughtHandler:GetDistinctMoodThoughtGroups (System.Collections.Generic.List`1<RimWorld.Thought>)
RimWorld.ThoughtHandler:TotalMoodOffset ()
RimWorld.Need_Mood:get_CurInstantLevel ()
CommonSense.Need_NeedInterval_CommonSensePatch:Postfix (RimWorld.Need_Mood)
(wrapper dynamic-method) RimWorld.Need_Mood:RimWorld.Need_Mood.NeedInterval_Patch1 (RimWorld.Need_Mood)
RimWorld.Pawn_NeedsTracker:NeedsTrackerTick ()
(wrapper dynamic-method) Verse.Pawn:Verse.Pawn.Tick_Patch1 (Verse.Pawn)
RimWorld.TradeShip:PassingShipTick ()
RimWorld.PassingShipManager:PassingShipManagerTick ()
(wrapper dynamic-method) Verse.Map:Verse.Map.MapPostTick_Patch3 (Verse.Map)
(wrapper dynamic-method) Verse.TickManager:Verse.TickManager.DoSingleTick_Patch2 (Verse.TickManager)
Verse.TickManager:TickManagerUpdate ()

Ok... so that's a big ol pile of other people's code. But it seems like it's kicked off from Need_NeedInterval_CommonSensePatch:Postfix reading a current need level from a pawn in a trade ship... and that seems like you could probably bail out of the method earlier and avoid their bugs. Maybe check to see if the pawn isn't on the current map, or isn't spawned, or something? I don't know exactly which property you'd check.

Based on the error it seems likely that it could happen for most worldpawns, not just tradeship pawns, but who knows.

Alright, sounds simple enough.
Pawn being on the trade ship having ticks did throw me off haha.

Done that.