Fixed freezing after siege due to Infinite Loop bug in BKSettlementBehaviour - #205
Open
tenttomi wants to merge 1 commit into
Open
Fixed freezing after siege due to Infinite Loop bug in BKSettlementBehaviour#205tenttomi wants to merge 1 commit into
tenttomi wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In the
SiegeConsequencesmethod inBKSettlementBehaviourclass, an infinite loop could occur when attempting to reduce the population after a siege, resulting the game freezing. This happened due to a specific edge case in population type selection:0, meaning it could never be chosen.0.ChooseWeighted()only picks from weighted options, it never selected the only type that had remaining population.finalNum = 0every iteration, preventingtoKillfrom decreasing.weightsis apparently derived from demand, and it is possible for a type to have 0 from the returned numberexample of values of this case hapenning from debugger


The fix changes the way population is decreased. Instead of iteratively, now the kill distribution is calculated based on the weight proportions of each population type, still adhering to
weightsused before. Previously, If a population type runs out, the while loop continues which contributes to the issue discussed above. Now instead of loop, any unallocated kills due to low population counts (i.e. when kill for a type is more than that type count) are redistributed proportionally across all remaining population classes, to deal with edge cases like above.