Game Freezes When New Faction Enters Map

Started by larSyn, January 04, 2018, 09:35:56 AM

Previous topic - Next topic

larSyn

So, I'm working on a companion mod for Smokeleaf Industry that adds a new faction for trading.  I have everything set and made, but when a visitor/caravan enters the map the game freezes for a minute or so and I get this error:

{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset0 Calibri;}}
{\*\generator Riched20 10.0.15063}\viewkind4\uc1
\pard\sa200\sl276\slmult1\f0\fs22\lang9 Exception while generating pawn group: System.OutOfMemoryException: Out of memory\par
  at (wrapper managed-to-native) object:__icall_wrapper_mono_array_new_specific (intptr,int)\par
  at System.Array.Resize[PawnGenOption] (RimWorld.PawnGenOption[]& array, Int32 length, Int32 newSize) [0x00000] in <filename unknown>:0 \par
  at System.Array.Resize[PawnGenOption] (RimWorld.PawnGenOption[]& array, Int32 newSize) [0x00000] in <filename unknown>:0 \par
  at System.Collections.Generic.List`1[RimWorld.PawnGenOption].set_Capacity (Int32 value) [0x00000] in <filename unknown>:0 \par
  at System.Collections.Generic.List`1[RimWorld.PawnGenOption].GrowIfNeeded (Int32 newCount) [0x00000] in <filename unknown>:0 \par
  at System.Collections.Generic.List`1[RimWorld.PawnGenOption].Add (RimWorld.PawnGenOption item) [0x00000] in <filename unknown>:0 \par
  at RimWorld.PawnGroupMakerUtility.ChoosePawnGenOptionsByPoints (Single points, System.Collections.Generic.List`1 options, RimWorld.PawnGroupMakerParms parms) [0x00000] in <filename unknown>:0 \par
  at RimWorld.PawnGroupKindWorker_Normal.CanGenerateFrom (RimWorld.PawnGroupMakerParms parms, RimWorld.PawnGroupMaker groupMaker) [0x00000] in <filename unknown>:0 \par
  at RimWorld.PawnGroupMaker.CanGenerateFrom (RimWorld.PawnGroupMakerParms parms) [0x00000] in <filename unknown>:0 \par
  at RimWorld.PawnGroupMakerUtility+<GeneratePawns>c__Iterator0+<GeneratePawns>c__AnonStorey1.<>m__0 (RimWorld.PawnGroupMaker gm) [0x00000] in <filename unknown>:0 \par
  at System.Linq.Enumerable+<CreateWhereIterator>c__Iterator1D`1[RimWorld.PawnGroupMaker].MoveNext () [0x00000] in <filename unknown>:0 \par
  at Verse.GenCollection.TryRandomElementByWeight[PawnGroupMaker] (IEnumerable`1 source, System.Func`2 weightSelector, RimWorld.PawnGroupMaker& result) [0x00000] in <filename unknown>:0 \par
  at RimWorld.PawnGroupMakerUtility+<GeneratePawns>c__Iterator0.MoveNext () [0x00000] in <filename unknown>:0 \par
  at System.Collections.Generic.List`1[Verse.Pawn].AddEnumerable (IEnumerable`1 enumerable) [0x00000] in <filename unknown>:0 \par
  at System.Collections.Generic.List`1[Verse.Pawn]..ctor (IEnumerable`1 collection) [0x00000] in <filename unknown>:0 \par
  at System.Linq.Enumerable.ToList[Pawn] (IEnumerable`1 source) [0x00000] in <filename unknown>:0 \par
  at RimWorld.IncidentWorker_NeutralGroup.SpawnPawns (RimWorld.IncidentParms parms) [0x00000] in <filename unknown>:0 \par
  at RimWorld.IncidentWorker_VisitorGroup.TryExecuteWorker (RimWorld.IncidentParms parms) [0x00000] in <filename unknown>:0 \par
  at RimWorld.IncidentWorker.TryExecute (RimWorld.IncidentParms parms) [0x00000] in <filename unknown>:0 \par
  at RimWorld.Storyteller.TryFire (RimWorld.FiringIncident fi) [0x00000] in <filename unknown>:0 \par
  at RimWorld.Storyteller.StorytellerTick () [0x00000] in <filename unknown>:0 \par
  at Verse.TickManager.DoSingleTick () [0x00000] in <filename unknown>:0 \par
Verse.Log:Error(String)\par
RimWorld.PawnGroupKindWorker:GeneratePawns(PawnGroupMakerParms, PawnGroupMaker, Boolean)\par
RimWorld.PawnGroupMaker:GeneratePawns(PawnGroupMakerParms, Boolean)\par
RimWorld.<GeneratePawns>c__Iterator0:MoveNext()\par
System.Collections.Generic.List`1:AddEnumerable(IEnumerable`1)\par
System.Collections.Generic.List`1:.ctor(IEnumerable`1)\par
System.Linq.Enumerable:ToList(IEnumerable`1)\par
RimWorld.IncidentWorker_NeutralGroup:SpawnPawns(IncidentParms)\par
RimWorld.IncidentWorker_TraderCaravanArrival:TryExecuteWorker(IncidentParms)\par
RimWorld.IncidentWorker:TryExecute(IncidentParms)\par
RimWorld.Storyteller:TryFire(FiringIncident)\par
RimWorld.IncidentQueue:IncidentQueueTick()\par
RimWorld.Storyteller:StorytellerTick()\par
Verse.TickManager:DoSingleTick()\par
Verse.TickManager:TickManagerUpdate()\par
Verse.Game:UpdatePlay()\par
Verse.Root_Play:Update()\par
}


Or, it just freezes then crashes and I get the "Too Many Heaps" warning.  I'm pretty sure that it has something to do with the pawnGroupMaker, but after comparing to other mods and core factions, I can't find anything wrong.  I have the feeling I'm missing something simple...  :-\  Just wanted to see if anyone could help me figure this one out.  If anyone wants to see my faction/pawn xml let me know and I'll post it.  Thanks in advance.

BrokenValkyrie

#1
Does this happen often? How many faction is there on your map?

Either there too many faction or you simple don't have enough RAM. I had this happen once when my game session ran for a long time.

#Edit
On a second take it seems you are generating too many pawns. Either exceeding the stack size or the capability of your computer.

larSyn

Quote from: BrokenValkyrie on January 04, 2018, 09:52:31 AM
Does this happen often? How many faction is there on your map?

Either there too many faction or you simple don't have enough RAM. I had this happen once when my game session ran for a long time.

#Edit
On a second take it seems you are generating too many pawns. Either exceeding the stack size or the capability of your computer.

I have 16GB of RAM.  So I doubt there's a problem there.  I must be generating too many pawns as you suggested.  Is there a way to determine the stack size, so I don't go over it?  Here's my pawnGroupMaker code:


<pawnGroupMakers>
<li>
<kindDef>Normal</kindDef>
<options>
<DRSJunkie>50</DRSJunkie>
<DRSArsonist>15</DRSArsonist>
<DRSEnforcer>75</DRSEnforcer>
<DRSThug>100</DRSThug>
<DRSLieutenant>50</DRSLieutenant>
<DRSHitman>100</DRSHitman>
<DRSBodyguard>150</DRSBodyguard>
<DRSKingpin>5</DRSKingpin>
</options>
</li>
<li>
<kindDef>Trader</kindDef>
<traders>
<DRSDealer>1</DRSDealer>
</traders>
<carriers>
<Muffalo>6</Muffalo>
          <Dromedary>5</Dromedary>
          <Alpaca>2</Alpaca>
          <Elephant>2</Elephant>
</carriers>
<guards>
<DRSArsonist>15</DRSArsonist>
<DRSEnforcer>80</DRSEnforcer>
<DRSThug>100</DRSThug>
<DRSHitman>100</DRSHitman>
<DRSBodyguard>100</DRSBodyguard>
</guards>
</li>
<li>
<kindDef>FactionBase</kindDef>
<options>
<DRSKingpin>50</DRSKingpin>
<DRSArsonist>15</DRSArsonist>
<DRSEnforcer>100</DRSEnforcer>
<DRSJunkie>50</DRSJunkie>
<DRSThug>100</DRSThug>
<DRSLieutenant>100</DRSLieutenant>
<DRSHitman>100</DRSHitman>
<DRSBodyguard>100</DRSBodyguard>
<DRSDealer>15</DRSDealer>
</options>
</li>
</pawnGroupMakers>


Not sure what is different/wrong with it.  I've seen other mods have their pawn spawn chance numbers higher and lower and with more or less pawns.  I've been comparing it with Project Fallout's Vault factions, the Argonians mod, Rimsenal 's Ferals and the core Outlander faction and I can't figure it out...

Thanks for looking.

BrokenValkyrie

I can't find anything wrong. I think you should post the faction and pawn xml.

I got one theory, you might forgot to set combatPower of pawn. If combatPower of pawn are 0, the game won't stop adding pawn because it will never reach the point value.

Good luck finding the issue.

larSyn

Quote from: BrokenValkyrie on January 04, 2018, 11:06:45 AM
I can't find anything wrong. I think you should post the faction and pawn xml.

I got one theory, you might forgot to set combatPower of pawn. If combatPower of pawn are 0, the game won't stop adding pawn because it will never reach the point value.

Good luck finding the issue.

You were totally right.  I forgot to set combatPower for one pawn type.  The caravan showed up as it should have after that.  Thanks for your help!