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:
gfgtdf 2024-11-25 04:09:14 +01:00
parent a5dae832c8
commit 73c14e0d2b

View file

@ -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"));
}
}