emipa606 / GradualRomance

A relationship mod for Rimworld
MIT License
1 stars 1 forks source link

Pawn's attraction records is modified while iterating through it. #1

Closed thailyn closed 10 months ago

thailyn commented 10 months ago

I'm periodically getting this error that the RocketMan mod is catching ("Dumbo" is the name of one of my colonists).

Soyuz caught this error. Please don't report this to the RocketMan team unless you're certain RocketMan caused this error. with error System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
  at System.Collections.Generic.Dictionary`2+KeyCollection+Enumerator[TKey,TValue].MoveNext () [0x00013] in <eae584ce26bc40229c1b1aa476bfa589>:0 
  at Gradual_Romance.GRPawnComp.CleanAttractionRecords () [0x00030] in <e6ca08a97ecb4eb1b05ba3314aee9a25>:0 
  at Gradual_Romance.GRPawnComp.CompTick () [0x000df] in <e6ca08a97ecb4eb1b05ba3314aee9a25>:0 
  at Verse.ThingWithComps.Tick () [0x00024] in <95de19971c5d40878d8742747904cdcd>:0 
  at (wrapper dynamic-method) Verse.Pawn.Verse.Pawn.Tick_Patch4(Verse.Pawn) 
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 39)

Exception ticking Dumbo (at (130, 0, 167)): System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
  at (wrapper dynamic-method) Verse.Pawn.Verse.Pawn.Tick_Patch4(Verse.Pawn)
  at (wrapper dynamic-method) Verse.TickList.Verse.TickList.Tick_Patch2(Verse.TickList) 
(Filename: C:\buildslave\unity\build\Runtime/Export/Debug/Debug.bindings.h Line: 39)

The error is happening in this method: https://github.com/emipa606/GradualRomance/blob/3de4ced57f214e7cf22f917321c5f84992c2e432/Source/Gradual%20Romance/GRPawnComp.cs#L99-L109

I think it is a straightforward bug to fix, such as by caching the items to remove from the dictionary until after the foreach loop is done.

(I've been getting a bunch of errors from this mod recently (likely due at least in part to running several relationship mods at once), so I'll probably have some more bugs to file soon as I work through them, but this looked like an easy first report.)

emipa606 commented 10 months ago

Should be fixed in b038562, thanks for the detailed report!