From 8b111a2a76ea8ef098fac911bad33ad000eeefca Mon Sep 17 00:00:00 2001 From: Gunter Labes Date: Sat, 4 Nov 2023 21:27:44 +0100 Subject: [PATCH] Avoid accessing data of potentially killed unit Fixes #8019. --- data/lua/wml/harm_unit.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/data/lua/wml/harm_unit.lua b/data/lua/wml/harm_unit.lua index 1cd95ab0804..c647f67bbe2 100644 --- a/data/lua/wml/harm_unit.lua +++ b/data/lua/wml/harm_unit.lua @@ -176,6 +176,7 @@ function wml_actions.harm_unit(cfg) end end + local unit_to_harm_id = unit_to_harm.id if kill ~= false and unit_to_harm.hitpoints <= 0 then wml_actions.kill { id = unit_to_harm.id, animate = toboolean( animate ), fire_event = fire_event, harmer and T.secondary_unit { id = harmer.id } } end @@ -185,7 +186,7 @@ function wml_actions.harm_unit(cfg) end if variable then - wml.variables[string.format("%s[%d]", variable, index - 1)] = { id = unit_to_harm.id, harm_amount = damage } + wml.variables[string.format("%s[%d]", variable, index - 1)] = { id = unit_to_harm_id, harm_amount = damage } end -- both units may no longer be alive at this point, so double check