In Progress [1.3 / Beta 1.4] Crash on Assigning NPC Lords Focus Points

Users who are viewing this thread

Issue:
There is a bug in the code which assigns focus points for lords. This is in the CharacterDevelopmentCampaignBehaivor.DistributeUnspentFocusPoints method (in the TaleWorlds.CampaignSystem.SandBox.CampaignBehaviors.Towns namespace). This causes a crash in situations where a lord doesn't have any valid skills that can have a focus point applied to them.
81480350-80c61100-9229-11ea-97cc-16820962c95f.png

Cause:
The issue is that a null reference (for a SkillObject) is being passed as a key to a dictionary.
CIbQGrf.png

The weightFunction delegate can return a value that is less than 0 in some situations. This causes MBRandom.ChooseWeighted to return a null reference, which in turn causes an ArgumentNullException in the HeroDeveloper.AddFocus method.
Solution:
Make sure that the weightFunction delegate does not return a value below 0.
gtflEw9.png

This will allow MBRandom.ChooseWeighted to be able to correctly return a SkillObject.
Bug Reproduction In-Game:
It is probably unlikely this would occur in an un-modded game as it would require a large amount of time for the lord to gain enough focus points to cause the error. To reproduce the bug in a time-efficient manner, change the number of Focus points gained per level to 100. The game will crash immediately when trying to start a new campaign and will crash once a lord levels-up in an existing game. Both crashes will be because of the error detailed above.
 
This kept happening to me until I set focus points per level to 2 for bannerlord tweaks. haven't crashed for hours since. also make sure you go back far enough into your saves so it takes effect. anything above 2 focus points per level seems to crash for me atleast.
 
Yeah, I just spent a little while this morning debugging the issue (I'm the author for Bannerlord Tweaks). I've created a patch in Bannerlord Tweaks which fixes the issue but it would be better to have it implemented in native. You'll still get the crash eventually if you play the campaign for long enough (2 focus points per level means the crash will occur in half the time it would in native).
 
Back
Top Bottom