fix possible crash in undo events

This commit is contained in:
gfgtdf 2024-11-28 00:36:26 +01:00
parent 73c14e0d2b
commit 8a91549fe8
2 changed files with 21 additions and 13 deletions

View file

@ -171,15 +171,14 @@ bool undo_event::undo(int)
assert(resources::lua_kernel);
assert(resources::gamedata);
config::attribute_value& x1 = resources::gamedata->get_variable("x1");
config::attribute_value& y1 = resources::gamedata->get_variable("y1");
config::attribute_value& x2 = resources::gamedata->get_variable("x2");
config::attribute_value& y2 = resources::gamedata->get_variable("y2");
int oldx1 = x1.to_int(), oldy1 = y1.to_int(), oldx2 = x2.to_int(), oldy2 = y2.to_int();
x1 = e.filter_loc1.wml_x();
y1 = e.filter_loc1.wml_y();
x2 = e.filter_loc2.wml_x();
y2 = e.filter_loc2.wml_y();
config::attribute_value x1 = config::attribute_value::create(e.filter_loc1.wml_x());
config::attribute_value y1 = config::attribute_value::create(e.filter_loc1.wml_y());
config::attribute_value x2 = config::attribute_value::create(e.filter_loc2.wml_x());
config::attribute_value y2 = config::attribute_value::create(e.filter_loc2.wml_y());
std::swap(x1, resources::gamedata->get_variable("x1"));
std::swap(y1, resources::gamedata->get_variable("y1"));
std::swap(x2, resources::gamedata->get_variable("x2"));
std::swap(y2, resources::gamedata->get_variable("y2"));
std::unique_ptr<scoped_xy_unit> u1, u2;
if(unit_ptr who = get_unit(e.uid1, e.id1)) {
@ -200,10 +199,10 @@ bool undo_event::undo(int)
}
sound::commit_music_changes();
x1 = oldx1;
y1 = oldy1;
x2 = oldx2;
y2 = oldy2;
std::swap(x1, resources::gamedata->get_variable("x1"));
std::swap(y1, resources::gamedata->get_variable("y1"));
std::swap(x2, resources::gamedata->get_variable("x2"));
std::swap(y2, resources::gamedata->get_variable("y2"));
return true;
}

View file

@ -128,6 +128,15 @@ public:
config_attribute_value& operator=(const std::string_view &v);
config_attribute_value& operator=(const t_string &v);
//TODO: should this be a normal constructor?
template<typename T>
static config_attribute_value create(const T val)
{
config_attribute_value res;
res = val;
return res;
}
template<typename... Args>
config_attribute_value& operator=(const std::chrono::duration<Args...>& v)
{