fix possible crash in capture events
its not safe to keep a reference to the owner_side variable since the event might remove it, which could lead to a crash when atempting to set it
This commit is contained in:
parent
a5dae832c8
commit
73c14e0d2b
1 changed files with 5 additions and 5 deletions
10
src/team.cpp
10
src/team.cpp
|
@ -440,9 +440,9 @@ game_events::pump_result_t team::get_village(const map_location& loc, const int
|
|||
game_events::pump_result_t res;
|
||||
|
||||
if(gamedata) {
|
||||
config::attribute_value& var = gamedata->get_variable("owner_side");
|
||||
const config::attribute_value old_value = var;
|
||||
var = owner_side;
|
||||
config::attribute_value var_owner_side;
|
||||
var_owner_side = owner_side;
|
||||
std::swap(var_owner_side, gamedata->get_variable("owner_side"));
|
||||
|
||||
// During team building, game_events pump is not guaranteed to exist yet. (At current revision.) We skip capture
|
||||
// events in this case.
|
||||
|
@ -450,10 +450,10 @@ game_events::pump_result_t team::get_village(const map_location& loc, const int
|
|||
res = resources::game_events->pump().fire("capture", loc);
|
||||
}
|
||||
|
||||
if(old_value.blank()) {
|
||||
if(var_owner_side.blank()) {
|
||||
gamedata->clear_variable("owner_side");
|
||||
} else {
|
||||
var = old_value;
|
||||
std::swap(var_owner_side, gamedata->get_variable("owner_side"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue