mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Use make_unique for TurnInfo in CGameHandler.
* Fixes use after free @CGameHandler.cpp:2093
This commit is contained in:
@@ -1539,10 +1539,9 @@ void CGameHandler::newTurn()
|
|||||||
|
|
||||||
NewTurn::Hero hth;
|
NewTurn::Hero hth;
|
||||||
hth.id = h->id;
|
hth.id = h->id;
|
||||||
auto ti = new TurnInfo(h, 1);
|
auto ti = make_unique<TurnInfo>(h, 1);
|
||||||
// TODO: this code executed when bonuses of previous day not yet updated (this happen in NewTurn::applyGs). See issue 2356
|
// TODO: this code executed when bonuses of previous day not yet updated (this happen in NewTurn::applyGs). See issue 2356
|
||||||
hth.move = h->maxMovePoints(gs->map->getTile(h->getPosition(false)).terType != ETerrainType::WATER, ti);
|
hth.move = h->maxMovePoints(gs->map->getTile(h->getPosition(false)).terType != ETerrainType::WATER, ti.get());
|
||||||
delete ti;
|
|
||||||
hth.mana = h->getManaNewTurn();
|
hth.mana = h->getManaNewTurn();
|
||||||
|
|
||||||
n.heroes.insert(hth);
|
n.heroes.insert(hth);
|
||||||
@@ -1994,11 +1993,10 @@ bool CGameHandler::moveHero( ObjectInstanceID hid, int3 dst, ui8 teleporting, bo
|
|||||||
tmh.movePoints = h->movement;
|
tmh.movePoints = h->movement;
|
||||||
|
|
||||||
//check if destination tile is available
|
//check if destination tile is available
|
||||||
auto ti = new TurnInfo(h);
|
auto ti = make_unique<TurnInfo>(h);
|
||||||
const bool canFly = ti->hasBonusOfType(Bonus::FLYING_MOVEMENT);
|
const bool canFly = ti->hasBonusOfType(Bonus::FLYING_MOVEMENT);
|
||||||
const bool canWalkOnSea = ti->hasBonusOfType(Bonus::WATER_WALKING);
|
const bool canWalkOnSea = ti->hasBonusOfType(Bonus::WATER_WALKING);
|
||||||
const int cost = CPathfinderHelper::getMovementCost(h, h->getPosition(), hmpos, nullptr, nullptr, h->movement, ti);
|
const int cost = CPathfinderHelper::getMovementCost(h, h->getPosition(), hmpos, nullptr, nullptr, h->movement, ti.get());
|
||||||
delete ti;
|
|
||||||
|
|
||||||
//it's a rock or blocked and not visitable tile
|
//it's a rock or blocked and not visitable tile
|
||||||
//OR hero is on land and dest is water and (there is not present only one object - boat)
|
//OR hero is on land and dest is water and (there is not present only one object - boat)
|
||||||
@@ -2090,14 +2088,14 @@ bool CGameHandler::moveHero( ObjectInstanceID hid, int3 dst, ui8 teleporting, bo
|
|||||||
|
|
||||||
if(!transit && embarking)
|
if(!transit && embarking)
|
||||||
{
|
{
|
||||||
tmh.movePoints = h->movementPointsAfterEmbark(h->movement, cost, false, ti);
|
tmh.movePoints = h->movementPointsAfterEmbark(h->movement, cost, false, ti.get());
|
||||||
return doMove(TryMoveHero::EMBARK, IGNORE_GUARDS, DONT_VISIT_DEST, LEAVING_TILE);
|
return doMove(TryMoveHero::EMBARK, IGNORE_GUARDS, DONT_VISIT_DEST, LEAVING_TILE);
|
||||||
// In H3 embark ignore guards
|
// In H3 embark ignore guards
|
||||||
}
|
}
|
||||||
|
|
||||||
if(disembarking)
|
if(disembarking)
|
||||||
{
|
{
|
||||||
tmh.movePoints = h->movementPointsAfterEmbark(h->movement, cost, true, ti);
|
tmh.movePoints = h->movementPointsAfterEmbark(h->movement, cost, true, ti.get());
|
||||||
return doMove(TryMoveHero::DISEMBARK, CHECK_FOR_GUARDS, VISIT_DEST, LEAVING_TILE);
|
return doMove(TryMoveHero::DISEMBARK, CHECK_FOR_GUARDS, VISIT_DEST, LEAVING_TILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user