diff --git a/client/GUIClasses.cpp b/client/GUIClasses.cpp index 466ec79e6..86f933048 100644 --- a/client/GUIClasses.cpp +++ b/client/GUIClasses.cpp @@ -3699,7 +3699,8 @@ CTavernWindow::CTavernWindow(const CGObjectInstance *TavernObj): { OBJ_CONSTRUCTION_CAPTURING_ALL; std::vector h = LOCPLINT->cb->getAvailableHeroes(TavernObj); - assert(h.size() == 2); + if(h.size() < 2) + h.resize(2, nullptr); h1 = new HeroPortrait(selected,0,72,299,h[0]); h2 = new HeroPortrait(selected,1,162,299,h[1]); diff --git a/lib/IGameCallback.cpp b/lib/IGameCallback.cpp index 654e5b494..3692c97cc 100644 --- a/lib/IGameCallback.cpp +++ b/lib/IGameCallback.cpp @@ -554,8 +554,8 @@ std::vector CGameInfoCallback::getAvailableHeroes(const std::vector ret; //ERROR_RET_VAL_IF(!isOwnedOrVisited(townOrTavern), "Town or tavern must be owned or visited!", ret); //TODO: town needs to be owned, advmap tavern needs to be visited; to be reimplemented when visit tracking is done - ret.resize(gs->players[*player].availableHeroes.size()); - std::copy(gs->players[*player].availableHeroes.begin(),gs->players[*player].availableHeroes.end(),ret.begin()); + range::copy(gs->players[*player].availableHeroes, std::back_inserter(ret)); + vstd::erase_if(ret, [](const CGHeroInstance *h) { return h == nullptr; }); return ret; }