Make sure no weak ptr expires when calculating ranking

This commit is contained in:
Benau 2018-06-08 11:04:58 +08:00
parent 1dcb8d3db6
commit e674f2d091
2 changed files with 7 additions and 5 deletions

View File

@ -80,7 +80,7 @@ public:
/** \brief Get the players that are in the game
* \return A vector containing pointers on the players profiles. */
std::vector<std::shared_ptr<NetworkPlayerProfile> >
getConnectedPlayers() const
getConnectedPlayers(bool same_offset = false) const
{
std::lock_guard<std::mutex> lock(m_players_mutex);
std::vector<std::shared_ptr<NetworkPlayerProfile> > players;
@ -88,6 +88,8 @@ public:
{
if (auto player_connected = player_weak.lock())
players.push_back(player_connected);
else if (same_offset)
players.push_back(nullptr);
}
return players;
} // getConnectedPlayers

View File

@ -888,7 +888,7 @@ void ServerLobby::computeNewRankings()
std::vector<double> scores_change;
std::vector<double> new_scores;
auto players = m_game_setup->getPlayers();
auto players = m_game_setup->getConnectedPlayers(true/*same_offset*/);
for (unsigned i = 0; i < players.size(); i++)
{
const uint32_t id = race_manager->getKartInfo(i).getOnlineId();
@ -918,7 +918,7 @@ void ServerLobby::computeNewRankings()
double ranking_importance = 0.0;
// No change between two quitting players
if (players[i].expired() && players[j].expired())
if (!players[i] && !players[j])
continue;
double player2_scores = new_scores[j];
@ -936,13 +936,13 @@ void ServerLobby::computeNewRankings()
double mode_factor = getModeFactor();
if (players[i].expired())
if (!players[i])
{
result = 0.0;
ranking_importance = mode_factor *
MAX_SCALING_TIME * MAX_POINTS_PER_SECOND * player_factors;
}
else if (players[j].expired())
else if (!players[j])
{
result = 1.0;
ranking_importance = mode_factor *