1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-09 13:14:02 +02:00

Fix crash on losing a hero

This commit is contained in:
Ivan Savenko 2024-10-10 21:16:41 +00:00
parent 1fc0267ad1
commit dfff1eae26

View File

@ -219,7 +219,12 @@ void PlayerLocalState::removeWanderingHero(const CGHeroInstance * hero)
if (hero == currentSelection)
{
auto const * nextHero = getNextWanderingHero(hero);
setSelection(nextHero);
if (nextHero)
setSelection(nextHero);
else if (!ownedTowns.empty())
setSelection(ownedTowns.front());
else
setSelection(nullptr);
}
vstd::erase(wanderingHeroes, hero);
@ -334,7 +339,8 @@ void PlayerLocalState::serialize(JsonNode & dest) const
dest["spellbook"]["tabBattle"].Integer() = spellbookSettings.spellbookLastTabBattle;
dest["spellbook"]["tabAdvmap"].Integer() = spellbookSettings.spellbookLastTabAdvmap;
dest["currentSelection"].Integer() = currentSelection->id;
if (currentSelection)
dest["currentSelection"].Integer() = currentSelection->id;
}
void PlayerLocalState::deserialize(const JsonNode & source)