Infinite loops when attacking vanilla pawns/modded building

Started by BabyLettuce, April 08, 2023, 09:18:21 AM

Previous topic - Next topic

BabyLettuce

I am currently developing a mod called CerebroCraft. It's actually on the workshop right now, but it's definitely "early access", and has a few relatively major bugs I have run into. The most glaring bug as of right now is a seemingly random one: infinite loops when pawns/raiders attack colonists and/or my modded buildings.

These errors are occurring with just my mod and the base game. The errors are the same with a more varied mod list.

The errors look as follows:
Exception in JobDriver tick for pawn Bang driver=JobDriver_AttackMelee (toilIndex=2) driver.job=(AttackMelee (Job_647277) A=Thing_Human321796)
System.NullReferenceException: Object reference not set to an instance of an object
  at Verse.Tool.AdjustedBaseMeleeDamageAmount (Verse.Thing ownerEquipment, Verse.DamageDef damageDef) [0x0002c] in <3cca3e6203e64b109fd8ce21f7120d03>:0
  at Verse.VerbProperties.AdjustedMeleeDamageAmount (Verse.Tool tool, Verse.Pawn attacker, Verse.Thing equipment, Verse.HediffComp_VerbGiver hediffCompSource) [0x00020] in <3cca3e6203e64b109fd8ce21f7120d03>:0
  at Verse.VerbProperties.AdjustedMeleeDamageAmount (Verse.Verb ownerVerb, Verse.Pawn attacker) [0x00038] in <3cca3e6203e64b109fd8ce21f7120d03>:0
  at Verse.VerbUtility.DPS (Verse.Verb v, Verse.Pawn p) [0x00000] in <3cca3e6203e64b109fd8ce21f7120d03>:0
  at Verse.VerbUtility.InitialVerbWeight (Verse.Verb v, Verse.Pawn p) [0x00000] in <3cca3e6203e64b109fd8ce21f7120d03>:0
  at RimWorld.Pawn_MeleeVerbs.GetUpdatedAvailableVerbsList (System.Boolean terrainTools) [0x0028e] in <3cca3e6203e64b109fd8ce21f7120d03>:0
  at RimWorld.Pawn_MeleeVerbs.ChooseMeleeVerb (Verse.Thing target) [0x00018] in <3cca3e6203e64b109fd8ce21f7120d03>:0
  at RimWorld.Pawn_MeleeVerbs.TryGetMeleeVerb (Verse.Thing target) [0x00047] in <3cca3e6203e64b109fd8ce21f7120d03>:0
  at RimWorld.Pawn_MeleeVerbs.TryMeleeAttack (Verse.Thing target, Verse.Verb verbToUse, System.Boolean surpriseAttack) [0x00079] in <3cca3e6203e64b109fd8ce21f7120d03>:0
  at Verse.AI.JobDriver_AttackMelee.<MakeNewToils>b__3_1 () [0x0003c] in <3cca3e6203e64b109fd8ce21f7120d03>:0
  at Verse.AI.Toils_Combat+<>c__DisplayClass6_0.<FollowAndMeleeAttack>b__0 () [0x000e8] in <3cca3e6203e64b109fd8ce21f7120d03>:0
  at Verse.AI.JobDriver.DriverTick () [0x00163] in <3cca3e6203e64b109fd8ce21f7120d03>:0
UnityEngine.StackTraceUtility:ExtractStackTrace ()
Verse.Log:Error (string)
Verse.AI.JobUtility:TryStartErrorRecoverJob (Verse.Pawn,string,System.Exception,Verse.AI.JobDriver)
Verse.AI.JobDriver:DriverTick ()
Verse.AI.Pawn_JobTracker:JobTrackerTick ()
Verse.Pawn:Tick ()
Verse.TickList:Tick ()
Verse.TickManager:DoSingleTick ()
Verse.TickManager:TickManagerUpdate ()
(wrapper dynamic-method) Verse.Game:Verse.Game.UpdatePlay_Patch1 (Verse.Game)
Verse.Root_Play:Update ()

AND:

JobDriver threw exception in toil MakeNewToils's initAction for pawn Bang driver=JobDriver_Wait (toilIndex=0) driver.job=(Wait (Job_647278))
System.NullReferenceException: Object reference not set to an instance of an object
  at Verse.Tool.AdjustedBaseMeleeDamageAmount (Verse.Thing ownerEquipment, Verse.DamageDef damageDef) [0x0002c] in <3cca3e6203e64b109fd8ce21f7120d03>:0
  at Verse.VerbProperties.AdjustedMeleeDamageAmount (Verse.Tool tool, Verse.Pawn attacker, Verse.Thing equipment, Verse.HediffComp_VerbGiver hediffCompSource) [0x00020] in <3cca3e6203e64b109fd8ce21f7120d03>:0
  at Verse.VerbProperties.AdjustedMeleeDamageAmount (Verse.Verb ownerVerb, Verse.Pawn attacker) [0x00038] in <3cca3e6203e64b109fd8ce21f7120d03>:0
  at Verse.VerbUtility.DPS (Verse.Verb v, Verse.Pawn p) [0x00000] in <3cca3e6203e64b109fd8ce21f7120d03>:0
  at Verse.VerbUtility.InitialVerbWeight (Verse.Verb v, Verse.Pawn p) [0x00000] in <3cca3e6203e64b109fd8ce21f7120d03>:0
  at RimWorld.Pawn_MeleeVerbs.GetUpdatedAvailableVerbsList (System.Boolean terrainTools) [0x0028e] in <3cca3e6203e64b109fd8ce21f7120d03>:0
  at RimWorld.Pawn_MeleeVerbs.ChooseMeleeVerb (Verse.Thing target) [0x00018] in <3cca3e6203e64b109fd8ce21f7120d03>:0
  at RimWorld.Pawn_MeleeVerbs.TryGetMeleeVerb (Verse.Thing target) [0x00047] in <3cca3e6203e64b109fd8ce21f7120d03>:0
  at RimWorld.Pawn_MeleeVerbs.TryMeleeAttack (Verse.Thing target, Verse.Verb verbToUse, System.Boolean surpriseAttack) [0x00079] in <3cca3e6203e64b109fd8ce21f7120d03>:0
  at Verse.AI.JobDriver_Wait.CheckForAutoAttack () [0x00130] in <3cca3e6203e64b109fd8ce21f7120d03>:0
  at Verse.AI.JobDriver_Wait.<MakeNewToils>b__3_0 () [0x0003d] in <3cca3e6203e64b109fd8ce21f7120d03>:0
  at Verse.AI.JobDriver.TryActuallyStartNextToil () [0x001b0] in <3cca3e6203e64b109fd8ce21f7120d03>:0
UnityEngine.StackTraceUtility:ExtractStackTrace ()
Verse.Log:Error (string)
Verse.AI.JobUtility:TryStartErrorRecoverJob (Verse.Pawn,string,System.Exception,Verse.AI.JobDriver)
Verse.AI.JobDriver:TryActuallyStartNextToil ()
Verse.AI.JobDriver:ReadyForNextToil ()
Verse.AI.Pawn_JobTracker:StartJob (Verse.AI.Job,Verse.AI.JobCondition,Verse.AI.ThinkNode,bool,bool,Verse.ThinkTreeDef,System.Nullable`1<Verse.AI.JobTag>,bool,bool,System.Nullable`1<bool>,bool,bool)
Verse.AI.JobUtility:TryStartError


AND:
An error occurred while starting an error recover job. We have to stop now to avoid infinite loops. This means that the pawn is now jobless which can cause further bugs. pawn=Bang
UnityEngine.StackTraceUtility:ExtractStackTrace ()
Verse.Log:Error (string)
Verse.AI.JobUtility:TryStartErrorRecoverJob (Verse.Pawn,string,System.Exception,Verse.AI.JobDriver)
Verse.AI.JobDriver:TryActuallyStartNextToil ()
Verse.AI.JobDriver:ReadyForNextToil ()
Verse.AI.Pawn_JobTracker:StartJob (Verse.AI.Job,Verse.AI.JobCondition,Verse.AI.ThinkNode,bool,bool,Verse.ThinkTreeDef,System.Nullable`1<Verse.AI.JobTag>,bool,bool,System.Nullable`1<bool>,bool,bool)
Verse.AI.JobUtility:TryStartErrorRecoverJob (Verse.Pawn,string,System.Exception,Verse.AI.JobDriver)
Verse.AI.JobDriver:DriverTick ()
Verse.AI.Pawn_JobTracker:JobTrackerTick ()
Verse.Pawn:Tick ()
Verse.TickList:Tick ()
Verse.TickManager:DoSingleTick ()
Verse.TickManager:TickManagerUpdate ()
(wrapper dynamic-method) Verse.Game:Verse.Game.UpdatePlay_Patch1 (Verse.Game)
Verse.Root_Play:Update ()

The errors will sometimes differ, but it generally revolves around null exception errors for the most random objects. Most often it occurs randomly during attacking or when it involves custom buildings; however, I have had it throw null exceptions when raiders target BATTERIES!

When I draft a colonist and have them target the modded buildings sometimes they behave totally normally, and sometimes the error spams until the forced attack is terminated by the player. Without the dev mode enabled most of the gameplay resolves itself as the game attempts to fix itself, but these errors should absolutely be nipped in the bud ASAP.

PLEASE let me know if you can help me in anyway prior to having to show the large chunks of code that have gone into this mod.

Thank you all!

I understand it will very likely be hard to find out the source of the error without