Skip to content

Commit fc33af2

Browse files
authored
Fix exception while cleaning up title history (#2786) #patch
Replaces Min with OrderBy and FirstOrDefault to select the next valid liege holder date. This improves clarity and ensures correct handling when no suitable date is found.
1 parent ee02d66 commit fc33af2

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

ImperatorToCK3/CK3/Titles/LandedTitles.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,9 @@ public void CleanUpHistory(CharacterCollection characters, Date ck3BookmarkDate)
494494
liegeTitle.History.Fields.TryGetValue("holder", out var liegeHolderField);
495495
Date? laterDate = liegeHolderField?.DateToEntriesDict
496496
.Where(kvp => kvp.Key > date && kvp.Key <= ck3BookmarkDate && kvp.Value.Count != 0 && kvp.Value[^1].Value.ToString() != "0")
497-
.Min(kvp => kvp.Key);
497+
.OrderBy(kvp => kvp.Key)
498+
.Select(kvp => (Date?)kvp.Key)
499+
.FirstOrDefault(defaultValue: null);
498500

499501
if (laterDate == null) {
500502
liegeField.DateToEntriesDict.Remove(date);

0 commit comments

Comments
 (0)