fix(Core/Taxi): Fixes crash when player logins and continues flight (#18270)

* fix(Core/Taxi): Fixes crash when player logins and continue flight

* Update WaypointMovementGenerator.cpp
This commit is contained in:
Anton Popovichenko
2024-02-12 12:18:05 +01:00
committed by GitHub
parent a4dc083b42
commit 72e75982be

View File

@@ -347,6 +347,27 @@ void FlightPathMovementGenerator::LoadPath(Player* player)
_pointsForPathSwitch.push_back({ uint32(i_path.size() - 1), int32(ceil(cost * discount)) });
}
// TODO: fixes crash, but can be handled in a better way once we will know how to reproduce it.
if (GetCurrentNode() >= i_path.size())
{
std::string paths;
std::deque<uint32> const& taxi = player->m_taxi.GetPath();
for (uint32 src = 0, dst = 1; dst < taxi.size(); src = dst++)
{
uint32 path, cost;
sObjectMgr->GetTaxiPath(taxi[src], taxi[dst], path, cost);
paths += std::to_string(path) + " ";
}
LOG_ERROR("movement.flightpath", "Failed to build correct path for player: {}. Current node: {}, max nodes: {}. Paths: {}. Player pos: {}.", player->GetGUID().ToString(), GetCurrentNode(), i_path.size(), paths, player->GetPosition().ToString());
// Lets choose the second last element so that a player would still have some flight.
if (int(i_path.size()) - 2 >= 0)
i_currentNode = uint32(i_path.size() - 2);
else
i_currentNode = uint32(i_path.size() - 1);
}
}
void FlightPathMovementGenerator::DoInitialize(Player* player)