lilwhitemouse / RimWorld-LWM.DeepStorage

A mod for the game RimWorld that has a set of Deep Storage Units that allow storing more than one item at a location.
GNU General Public License v3.0
29 stars 36 forks source link

Exception when right clicking certain objects in 1.3 #110

Open jcstryker opened 3 years ago

jcstryker commented 3 years ago
Exception in RimWorld.FloatMenuMakerMap.ChoicesAtFor: System.InvalidOperationException: Sequence contains no matching element
  at System.Linq.Enumerable.First[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] predicate) [0x00011] in <351e49e2a5bf4fd6beabb458ce2255f3>:0 
  at RimWorld.RitualBehaviorWorker_Conversion.CanStartRitualNow (Verse.TargetInfo target, RimWorld.Precept_Ritual ritual, Verse.Pawn selectedPawn, System.Collections.Generic.Dictionary`2[TKey,TValue] forcedForRole) [0x0000b] in <8bc9a771920f4f8da0f2218f7c9cb0b0>:0 
  at Verse.Thing+<GetFloatMenuOptions>d__145.MoveNext () [0x0015e] in <8bc9a771920f4f8da0f2218f7c9cb0b0>:0 
  at Verse.ThingWithComps+<GetFloatMenuOptions>d__40.MoveNext () [0x00078] in <8bc9a771920f4f8da0f2218f7c9cb0b0>:0 
  at RimWorld.FloatMenuMakerMap.AddHumanlikeOrders (UnityEngine.Vector3 clickPos, Verse.Pawn pawn, System.Collections.Generic.List`1[T] opts) [0x0462d] in <8bc9a771920f4f8da0f2218f7c9cb0b0>:0 
     - transpiler LWM.DeepStorage: IEnumerable`1 LWM.DeepStorage.Patch_AddHumanlikeOrders:Transpiler(IEnumerable`1 instructions)
     - prefix LWM.DeepStorage: Boolean LWM.DeepStorage.Patch_AddHumanlikeOrders:Prefix(Vector3 clickPos, Pawn pawn, List`1 opts)
     - postfix OskarPotocki.HeavyWeapons: Void HeavyWeapons.Patch_FloatMenuMakerMap+AddHumanlikeOrders_Fix:Postfix(Vector3 clickPos, Pawn pawn, List`1& opts)
     - postfix OskarPotocki.VFECore: Void VFECore.Patch_FloatMenuMakerMap+AddHumanlikeOrders_Fix:Postfix(Vector3 clickPos, Pawn pawn, List`1& opts)
     - postfix LWM.DeepStorage: Void LWM.DeepStorage.Patch_AddHumanlikeOrders:Postfix(List`1 opts)
  at RimWorld.FloatMenuMakerMap.ChoicesAtFor (UnityEngine.Vector3 clickPos, Verse.Pawn pawn, System.Boolean suppressAutoTakeableGoto) [0x000db] in <8bc9a771920f4f8da0f2218f7c9cb0b0>:0 
     - postfix net.pardeike.rimworld.mods.achtung: Void AchtungMod.FloatMenuMakerMap_ChoicesAtFor_Postfix:Postfix(List`1 __result, Vector3 clickPos, Pawn pawn)
     - finalizer net.pardeike.rimworld.mods.achtung: Exception AchtungMod.FloatMenuMakerMap_ChoicesAtFor_Finalizer:Finalizer(Exception __exception, List`1& __result)
jtgibson01 commented 2 years ago

Having looked into this, I can definitively confirm the cause. This is a vanilla bug exposed by modding; the culprit is:

Precept_Role precept_Role = ritual.ideo.RolesListForReading.First((Precept_Role r) => r.def == PreceptDefOf.IdeoRole_Moralist);

in RimWorld.RitualBehaviorWorker_Conversion.CanStartRitualNow().

The IEnumerable<>.First() function automatically throws an exception if it doesn't find an element, whereas Tynan (or whoever else is programming at Ludeon, if he has a team now) should be using FirstOrDefault, and should be verifying against null in the next line too.

The cause is when you have an ideology assigned to your colony that doesn't have a spiritual leader role defined.