From 74111b76897f1d3c9627dbdfef441fce35be284f Mon Sep 17 00:00:00 2001 From: Vadim Markovtsev Date: Tue, 19 Jan 2016 10:30:55 +0300 Subject: [PATCH] Return missing building name instead of crashing in CComponent::getSubtitleInternal --- client/widgets/CComponent.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/client/widgets/CComponent.cpp b/client/widgets/CComponent.cpp index e1f0924e8..41f331539 100644 --- a/client/widgets/CComponent.cpp +++ b/client/widgets/CComponent.cpp @@ -186,19 +186,31 @@ std::string CComponent::getSubtitleInternal() case artifact: return CGI->arth->artifacts[subtype]->Name(); case experience: { - if (subtype == 1) //+1 level - tree of knowledge + if(subtype == 1) //+1 level - tree of knowledge { std::string level = CGI->generaltexth->allTexts[442]; boost::replace_first(level, "1", boost::lexical_cast(val)); return level; } else + { return boost::lexical_cast(val); //amount of experience OR level required for seer hut; + } } case spell: return CGI->spellh->objects[subtype]->name; case morale: return ""; case luck: return ""; - case building: return CGI->townh->factions[subtype]->town->buildings[BuildingID(val)]->Name(); + case building: + { + auto building = CGI->townh->factions[subtype]->town->buildings[BuildingID(val)]; + if(!building) + { + logGlobal->errorStream() << boost::format("Town of faction %s has no building #%d") + % CGI->townh->factions[subtype]->town->faction->name % val; + return (boost::format("Missing building #%d") % val).str(); + } + return building->Name(); + } case hero: return ""; case flag: return CGI->generaltexth->capColors[subtype]; }