1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Nullkiller: stabilization, fix memory leaks

This commit is contained in:
Andrii Danylchenko 2021-05-16 14:59:32 +03:00 committed by Andrii Danylchenko
parent 7e88819105
commit 45942cfbbe
3 changed files with 14 additions and 8 deletions

View File

@ -118,6 +118,7 @@ void Nullkiller::updateAiState(int pass)
activeHero = nullptr;
memory->removeInvisibleObjects(cb.get());
dangerHitMap->updateHitMap();
boost::this_thread::interruption_point();

View File

@ -88,7 +88,7 @@ std::string ObjectActor::toString() const
HeroActor::HeroActor(const CGHeroInstance * hero, HeroRole heroRole, uint64_t chainMask, const Nullkiller * ai)
:ChainActor(hero, heroRole, chainMask)
{
exchangeMap = new HeroExchangeMap(this, ai);
exchangeMap.reset(new HeroExchangeMap(this, ai));
setupSpecialActors();
}
@ -99,7 +99,7 @@ HeroActor::HeroActor(
const Nullkiller * ai)
:ChainActor(carrier, other, army)
{
exchangeMap = new HeroExchangeMap(this, ai);
exchangeMap.reset(new HeroExchangeMap(this, ai));
armyCost += army->armyCost;
actorAction = army->getActorAction();
setupSpecialActors();
@ -244,6 +244,11 @@ ChainActor * HeroActor::exchange(const ChainActor * specialActor, const ChainAct
return &result->specialActors[index];
}
HeroExchangeMap::HeroExchangeMap(const HeroActor * actor, const Nullkiller * ai)
:actor(actor), ai(ai)
{
}
HeroExchangeMap::~HeroExchangeMap()
{
for(auto & exchange : exchangeMap)
@ -339,7 +344,11 @@ HeroExchangeArmy * HeroExchangeMap::tryUpgrade(
}
if(target->getArmyStrength() <= army->getArmyStrength())
{
delete target;
return nullptr;
}
return target;
}

View File

@ -84,11 +84,7 @@ private:
const Nullkiller * ai;
public:
HeroExchangeMap(const HeroActor * actor, const Nullkiller * ai)
:actor(actor), ai(ai)
{
}
HeroExchangeMap(const HeroActor * actor, const Nullkiller * ai);
~HeroExchangeMap();
HeroActor * exchange(const ChainActor * other);
@ -106,7 +102,7 @@ public:
private:
ChainActor specialActors[SPECIAL_ACTORS_COUNT];
HeroExchangeMap * exchangeMap;
std::unique_ptr<HeroExchangeMap> exchangeMap;
void setupSpecialActors();