Don't dereference iterator after invalidating it

Found by coverity.
This commit is contained in:
Alexander van Gessel 2014-03-23 19:31:40 +01:00
parent ae34792417
commit 7df83c22a8

View File

@ -139,11 +139,6 @@ void recall::apply_temp_modifier(unit_map& unit_map)
std::vector<unit>& recalls = resources::teams->at(team_index()).recall_list();
std::vector<unit>::iterator it = find_if_matches_id(recalls, temp_unit_->id());
assert(it != recalls.end());
recalls.erase(it);
// Temporarily insert unit into unit_map
//unit map takes ownership of temp_unit
unit_map.insert(temp_unit_.release());
//Add cost to money spent on recruits.
int cost = resources::teams->at(team_index()).recall_cost();
@ -151,6 +146,12 @@ void recall::apply_temp_modifier(unit_map& unit_map)
cost = it->recall_cost();
}
recalls.erase(it);
// Temporarily insert unit into unit_map
//unit map takes ownership of temp_unit
unit_map.insert(temp_unit_.release());
resources::teams->at(team_index()).get_side_actions()->change_gold_spent_by(cost);
// Update gold in top bar
resources::screen->invalidate_game_status();