From 6301f79c5e306935c02a47a38f2c2799a05ec40c Mon Sep 17 00:00:00 2001 From: Seweryn Presnal Date: Tue, 10 Aug 2021 08:46:44 +0200 Subject: [PATCH] Fix for Imperator::Character::getCulture() causing crashes (#256) --- ImperatorToCK3/Source/CK3/Character/CK3Character.cpp | 5 +++-- .../Source/Imperator/Characters/Character.cpp | 2 +- .../Source/Imperator/Characters/Characters.cpp | 12 ++++++------ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/ImperatorToCK3/Source/CK3/Character/CK3Character.cpp b/ImperatorToCK3/Source/CK3/Character/CK3Character.cpp index 06418fb73..7694536eb 100644 --- a/ImperatorToCK3/Source/CK3/Character/CK3Character.cpp +++ b/ImperatorToCK3/Source/CK3/Character/CK3Character.cpp @@ -37,10 +37,11 @@ void CK3::Character::initializeFromImperator(std::shared_ptrgetSpouses().empty()) impProvForProvinceMapper = imperatorCharacter->getSpouses().begin()->second->getProvince(); - if (provinceMapper.getCK3ProvinceNumbers(impProvForProvinceMapper).empty()) + auto ck3ProvinceNumbers = provinceMapper.getCK3ProvinceNumbers(impProvForProvinceMapper); + if (ck3ProvinceNumbers.empty()) ck3Province = 0; else - ck3Province = provinceMapper.getCK3ProvinceNumbers(impProvForProvinceMapper)[0]; + ck3Province = ck3ProvinceNumbers[0]; auto match = religionMapper.match(imperatorCharacter->getReligion(), ck3Province, imperatorCharacter->getProvince()); if (match) diff --git a/ImperatorToCK3/Source/Imperator/Characters/Character.cpp b/ImperatorToCK3/Source/Imperator/Characters/Character.cpp index b5ded50f9..f66f6ded9 100644 --- a/ImperatorToCK3/Source/Imperator/Characters/Character.cpp +++ b/ImperatorToCK3/Source/Imperator/Characters/Character.cpp @@ -7,7 +7,7 @@ const std::string& Imperator::Character::getCulture() const { if (!culture.empty()) return culture; - if (family.first && !family.second->getCulture().empty()) + if (family.first && family.second && !family.second->getCulture().empty()) return family.second->getCulture(); return culture; } diff --git a/ImperatorToCK3/Source/Imperator/Characters/Characters.cpp b/ImperatorToCK3/Source/Imperator/Characters/Characters.cpp index a7f213bf7..3f8b6d11d 100644 --- a/ImperatorToCK3/Source/Imperator/Characters/Characters.cpp +++ b/ImperatorToCK3/Source/Imperator/Characters/Characters.cpp @@ -52,15 +52,15 @@ void Imperator::Characters::linkFamilies(const Families& theFamilies) { } } - std::string warningString = "Families without definition:"; + std::string logString = "Families without definition:"; if (!idsWithoutDefinition.empty()) { for (auto id : idsWithoutDefinition) { - warningString += " "; - warningString += std::to_string(id); - warningString += ","; + logString += " "; + logString += std::to_string(id); + logString += ","; } - warningString = warningString.substr(0, warningString.size() - 1); //remove last comma - Log(LogLevel::Warning) << warningString; + logString = logString.substr(0, logString.size() - 1); // remove last comma + Log(LogLevel::Info) << logString; } Log(LogLevel::Info) << "<> " << counter << " families linked to characters.";