1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +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; activeHero = nullptr;
memory->removeInvisibleObjects(cb.get()); memory->removeInvisibleObjects(cb.get());
dangerHitMap->updateHitMap(); dangerHitMap->updateHitMap();
boost::this_thread::interruption_point(); 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) HeroActor::HeroActor(const CGHeroInstance * hero, HeroRole heroRole, uint64_t chainMask, const Nullkiller * ai)
:ChainActor(hero, heroRole, chainMask) :ChainActor(hero, heroRole, chainMask)
{ {
exchangeMap = new HeroExchangeMap(this, ai); exchangeMap.reset(new HeroExchangeMap(this, ai));
setupSpecialActors(); setupSpecialActors();
} }
@@ -99,7 +99,7 @@ HeroActor::HeroActor(
const Nullkiller * ai) const Nullkiller * ai)
:ChainActor(carrier, other, army) :ChainActor(carrier, other, army)
{ {
exchangeMap = new HeroExchangeMap(this, ai); exchangeMap.reset(new HeroExchangeMap(this, ai));
armyCost += army->armyCost; armyCost += army->armyCost;
actorAction = army->getActorAction(); actorAction = army->getActorAction();
setupSpecialActors(); setupSpecialActors();
@@ -244,6 +244,11 @@ ChainActor * HeroActor::exchange(const ChainActor * specialActor, const ChainAct
return &result->specialActors[index]; return &result->specialActors[index];
} }
HeroExchangeMap::HeroExchangeMap(const HeroActor * actor, const Nullkiller * ai)
:actor(actor), ai(ai)
{
}
HeroExchangeMap::~HeroExchangeMap() HeroExchangeMap::~HeroExchangeMap()
{ {
for(auto & exchange : exchangeMap) for(auto & exchange : exchangeMap)
@@ -339,7 +344,11 @@ HeroExchangeArmy * HeroExchangeMap::tryUpgrade(
} }
if(target->getArmyStrength() <= army->getArmyStrength()) if(target->getArmyStrength() <= army->getArmyStrength())
{
delete target;
return nullptr; return nullptr;
}
return target; return target;
} }

View File

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