From 08f3a7d986aaed92bff5f8bcd7d449241116bbde Mon Sep 17 00:00:00 2001 From: IhateTrains Date: Sun, 24 Sep 2023 19:56:46 +0100 Subject: [PATCH] Don't throw exception on province beloning to an unloaded state (#1527) #patch --- ImperatorToCK3/Imperator/Provinces/ProvinceFactory.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ImperatorToCK3/Imperator/Provinces/ProvinceFactory.cs b/ImperatorToCK3/Imperator/Provinces/ProvinceFactory.cs index cdcc0bc1e..f1c1531b6 100644 --- a/ImperatorToCK3/Imperator/Provinces/ProvinceFactory.cs +++ b/ImperatorToCK3/Imperator/Provinces/ProvinceFactory.cs @@ -79,7 +79,11 @@ public static Province Parse(BufferedReader reader, ulong provinceId, StateColle provinceParser.ParseStream(reader); if (parsedStateId is not null) { - parsedProvince.State = states[parsedStateId.Value]; + if (!states.TryGetValue(parsedStateId.Value, out var state)) { + Logger.Warn($"Province {parsedProvince.Id} has state ID {parsedStateId}, but no such state has been loaded!"); + } else { + parsedProvince.State = state; + } } parsedProvince.TryLinkOwnerCountry(parsedOwnerId, countries);