mirror of
https://github.com/liyunfan1223/azerothcore-wotlk.git
synced 2026-08-08 07:48:02 +00:00
fix(Core/Movement): fix a small memory leak in RandomMovementGenerator (#20258)
* fix(Core/Movement): memory leak and possible crash Co-Authored-By: Ovahlord <18347559+ovahlord@users.noreply.github.com> * . * fix review --------- Co-authored-by: Ovahlord <18347559+ovahlord@users.noreply.github.com>
This commit is contained in:
@@ -29,15 +29,14 @@
|
|||||||
template<class T>
|
template<class T>
|
||||||
RandomMovementGenerator<T>::~RandomMovementGenerator() { }
|
RandomMovementGenerator<T>::~RandomMovementGenerator() { }
|
||||||
|
|
||||||
template<>
|
template RandomMovementGenerator<Creature>::~RandomMovementGenerator();
|
||||||
RandomMovementGenerator<Creature>::~RandomMovementGenerator()
|
|
||||||
{
|
|
||||||
delete _pathGenerator;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
void RandomMovementGenerator<Creature>::_setRandomLocation(Creature* creature)
|
void RandomMovementGenerator<Creature>::_setRandomLocation(Creature* creature)
|
||||||
{
|
{
|
||||||
|
if (!creature)
|
||||||
|
return;
|
||||||
|
|
||||||
if (creature->_moveState != MAP_OBJECT_CELL_MOVE_NONE)
|
if (creature->_moveState != MAP_OBJECT_CELL_MOVE_NONE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -135,7 +134,7 @@ void RandomMovementGenerator<Creature>::_setRandomLocation(Creature* creature)
|
|||||||
else // ground
|
else // ground
|
||||||
{
|
{
|
||||||
if (!_pathGenerator)
|
if (!_pathGenerator)
|
||||||
_pathGenerator = new PathGenerator(creature);
|
_pathGenerator = std::make_unique<PathGenerator>(creature);
|
||||||
else
|
else
|
||||||
_pathGenerator->Clear();
|
_pathGenerator->Clear();
|
||||||
|
|
||||||
@@ -242,6 +241,8 @@ void RandomMovementGenerator<Creature>::DoInitialize(Creature* creature)
|
|||||||
if (!_wanderDistance)
|
if (!_wanderDistance)
|
||||||
_wanderDistance = creature->GetWanderDistance();
|
_wanderDistance = creature->GetWanderDistance();
|
||||||
|
|
||||||
|
_pathGenerator.reset();
|
||||||
|
|
||||||
_nextMoveTime.Reset(creature->GetSpawnId() && creature->GetWanderDistance() == _wanderDistance ? urand(1, 5000) : 0);
|
_nextMoveTime.Reset(creature->GetSpawnId() && creature->GetWanderDistance() == _wanderDistance ? urand(1, 5000) : 0);
|
||||||
_wanderDistance = std::max((creature->GetWanderDistance() == _wanderDistance && creature->GetInstanceId() == 0) ? (creature->CanFly() ? MIN_WANDER_DISTANCE_AIR : MIN_WANDER_DISTANCE_GROUND) : 0.0f, _wanderDistance);
|
_wanderDistance = std::max((creature->GetWanderDistance() == _wanderDistance && creature->GetInstanceId() == 0) ? (creature->CanFly() ? MIN_WANDER_DISTANCE_AIR : MIN_WANDER_DISTANCE_GROUND) : 0.0f, _wanderDistance);
|
||||||
|
|
||||||
@@ -280,6 +281,7 @@ bool RandomMovementGenerator<Creature>::DoUpdate(Creature* creature, const uint3
|
|||||||
{
|
{
|
||||||
_nextMoveTime.Reset(0); // Expire the timer
|
_nextMoveTime.Reset(0); // Expire the timer
|
||||||
creature->StopMoving();
|
creature->StopMoving();
|
||||||
|
_pathGenerator.reset();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ private:
|
|||||||
TimeTrackerSmall _nextMoveTime;
|
TimeTrackerSmall _nextMoveTime;
|
||||||
uint8 _moveCount;
|
uint8 _moveCount;
|
||||||
float _wanderDistance;
|
float _wanderDistance;
|
||||||
PathGenerator* _pathGenerator;
|
std::unique_ptr<PathGenerator> _pathGenerator;
|
||||||
std::vector<G3D::Vector3> _destinationPoints;
|
std::vector<G3D::Vector3> _destinationPoints;
|
||||||
std::vector<uint8> _validPointsVector[RANDOM_POINTS_NUMBER + 1];
|
std::vector<uint8> _validPointsVector[RANDOM_POINTS_NUMBER + 1];
|
||||||
uint8 _currentPoint;
|
uint8 _currentPoint;
|
||||||
|
|||||||
Reference in New Issue
Block a user