Closed Daenyth closed 3 years ago
I'm suspicious of https://github.com/voult2/BetterPawnControl/blob/master/Source/Managers/AnimalManager.cs#L145 - I think x.zone
might be the null, because I have noticed that among all my animal mods I've managed to get some in state where no zone was selected before. I think this might be an interaction with the 'Area inclusion & exclusion' mod.
I'm able to use the Numbers mod animal tab as a workaround for now, I'll check that all animals have some assigned zone and if that makes the problem go away
It's not due to Area inclusion - I removed that to test, and the problem persists.
I cloned the project to open it in Rider, and looking at the source a bit more carefully, it seems like more likely the problem is that one of the AnimalLink
values in the links
argument is null.
If so, this might help; I'll try to figure out how to build and test on my world locally
- //get all links from the current map
- mapLinks = links.FindAll(x => x.mapId == currentMap);
- //get all links from the selected zone
- zoneLinks = mapLinks.FindAll(x => x.zone == policy.id);
+ //get all links from the current map
+ mapLinks = links.FindAll(x => x != null && x.mapId == currentMap);
+ //get all links from the selected zone
+ zoneLinks = mapLinks.FindAll(x => x != null && x.zone == policy.id);
OK, I was able to confirm that AnimalManager.links
contains a null
value by having PreOpen
for the tab invoke PrintAllAnimalPolicies
;
[BPC] ### List Animal links [67] ###
[BPC] Policy:0 Animal: Master: Area: FollowDrafted: False FollowFieldwork: False MapID: 0
[BPC] Policy:0 Animal: Cow69680 Master: Area: FollowDrafted: False FollowFieldwork: False MapID: 0
[BPC] Policy:1 Animal: Master: Area: FollowDrafted: False FollowFieldwork: False MapID: 0
[BPC] Policy:1 Animal: Cow69680 Master: Area: FollowDrafted: False FollowFieldwork: False MapID: 0
[BPC] Policy:0 Animal: Dromedary29608 Master: Area: FollowDrafted: False FollowFieldwork: False MapID: 0
[BPC] Policy:1 Animal: Dromedary29608 Master: Area: FollowDrafted: False FollowFieldwork: False MapID: 0
[BPC] Policy:0 Animal: Master: Area: FollowDrafted: False FollowFieldwork: False MapID: 0
[BPC] Policy:0 Animal: Master: Area: FollowDrafted: False FollowFieldwork: False MapID: 0
[BPC] Policy:1 Animal: Master: Area: FollowDrafted: False FollowFieldwork: False MapID: 0
[BPC] Policy:1 Animal: Master: Area: FollowDrafted: False FollowFieldwork: False MapID: 0
[BPC] Policy:0 Animal: Master: Area: RimWorld.Area_Home FollowDrafted: False FollowFieldwork: False MapID: 0
[BPC] Policy:0 Animal: Master: Area: FollowDrafted: False FollowFieldwork: False MapID: 0
[BPC] Policy:0 Animal: Master: Area: FollowDrafted: False FollowFieldwork: False MapID: 0
[BPC] Policy:0 Animal: Master: Area: FollowDrafted: False FollowFieldwork: False MapID: 0
[BPC] Policy:0 Animal: Master: Area: FollowDrafted: False FollowFieldwork: False MapID: 0
[BPC] Policy:0 Animal: Cow151497 Master: Area: FollowDrafted: False FollowFieldwork: False MapID: 0
Root level exception in OnGUI(): System.NullReferenceException: Object reference not set to an instance of an object
at BetterPawnControl.AnimalManager.PrintAllAnimalPolicies (System.String spacer) [0x00126] in <6c6ec8003e37446fbc185f6a5ee0140b>:0
at BetterPawnControl.MainTabWindow_Animals_Policies.PreOpen () [0x0000e] in <6c6ec8003e37446fbc185f6a5ee0140b>:0
at Verse.WindowStack.Add (Verse.Window window) [0x0001f] in <b9022531d79047b2b6baad3f7d519f01>:0
at (wrapper dynamic-method) RimWorld.MainTabsRoot.DMD<DMD<ToggleTab_Patch1>?-2069195392::ToggleTab_Patch1>(RimWorld.MainTabsRoot,RimWorld.MainButtonDef,bool)
at RimWorld.MainButtonWorker_ToggleTab.Activate () [0x00005] in <b9022531d79047b2b6baad3f7d519f01>:0
at RimWorld.MainButtonWorker.InterfaceTryActivate () [0x0004d] in <b9022531d79047b2b6baad3f7d519f01>:0
at (wrapper dynamic-method) RimWorld.MainButtonWorker.DMD<DMD<DoButton_Patch0>?-1203342208::DoButton_Patch0>(RimWorld.MainButtonWorker,UnityEngine.Rect)
at RimWorld.MainButtonsRoot.DoButtons () [0x0010c] in <b9022531d79047b2b6baad3f7d519f01>:0
at (wrapper dynamic-method) RimWorld.MainButtonsRoot.DMD<DMD<MainButtonsOnGUI_Patch1>?952941952::MainButtonsOnGUI_Patch1>(RimWorld.MainButtonsRoot)
at RimWorld.UIRoot_Play.UIRootOnGUI () [0x00037] in <b9022531d79047b2b6baad3f7d519f01>:0
at (wrapper dynamic-method) Verse.Root.DMD<DMD<OnGUI_Patch1>?1404324992::OnGUI_Patch1>(Verse.Root)
I'm not sure what happened, but my animal tab no longer displays (even though it used to work), and I get this error in my log: