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.
Cause:
The issue is that a null reference (for a SkillObject) is being passed as a key to a dictionary.
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.
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.
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.
Cause:
The issue is that a null reference (for a SkillObject) is being passed as a key to a dictionary.
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.
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.