From 6662c8bd0f479ea97a4b1dde270d5877985cc7b0 Mon Sep 17 00:00:00 2001 From: Batrachophreno Date: Thu, 14 Aug 2025 10:45:00 -0400 Subject: [PATCH] Space heater crash safety (#21182) Space heaters, when spawned via admin panel, will crash if if their TGUI is accessed immediately. This is because var/env is only initialized on process(), and if not initialized, the game will be very sad when the UI tries to display the current temperature by rounding a null value. Sets env on Initialize() and cleans up /ui_act() logic to prevent crash. --------- Signed-off-by: Batrachophreno --- code/game/machinery/spaceheater.dm | 8 +++++++- html/changelogs/bat-spaceheatercrashfix.yml | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 html/changelogs/bat-spaceheatercrashfix.yml diff --git a/code/game/machinery/spaceheater.dm b/code/game/machinery/spaceheater.dm index b2eea3bddeb..5a27072f023 100644 --- a/code/game/machinery/spaceheater.dm +++ b/code/game/machinery/spaceheater.dm @@ -8,7 +8,9 @@ use_power = POWER_USE_OFF clicksound = /singleton/sound_category/switch_sound var/on = FALSE + /// Currently heating or cooling the environment, if on. var/active = 0 + /// Force it to at least somewhat obey thermodynamics. var/heating_power = 40 KILO WATTS var/current_temperature var/set_temperature = T0C + 20 @@ -28,6 +30,8 @@ /obj/machinery/space_heater/Initialize() . = ..() cell = new(src) + /// Ensure env exists so TGUI doesn't attempt to round null for display. + env = loc.return_air() update_icon() /obj/machinery/space_heater/update_icon() @@ -112,13 +116,15 @@ /obj/machinery/space_heater/ui_data(mob/user) var/list/data = list() + current_temperature = round(env.temperature - T0C, 0.1) + data["power_cell_inserted"] = cell data["power_cell_charge"] = cell?.percent() data["is_on"] = on data["is_active"] = active data["panel_open"] = panel_open data["heating_power"] = heating_power - data["current_temperature"] = round(env.temperature - T0C, 0.1) + data["current_temperature"] = current_temperature data["set_temperature"] = set_temperature - T0C data["set_temperature_max"] = set_temperature_max - T0C data["set_temperature_min"] = set_temperature_min - T0C diff --git a/html/changelogs/bat-spaceheatercrashfix.yml b/html/changelogs/bat-spaceheatercrashfix.yml new file mode 100644 index 00000000000..32a4a35947f --- /dev/null +++ b/html/changelogs/bat-spaceheatercrashfix.yml @@ -0,0 +1,13 @@ +# Your name. +author: Batrachophrenoboocosmomachia + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, this gets changed to [] after reading. Just remove the brackets when you add new shit. +# Please surround your changes in double quotes ("). It works without them, but if you use certain characters it screws up compiling. The quotes will not show up in the changelog. +changes: + - bugfix: "Space heater gets env data on init for safety, to avoid TGUI edge case crash from attempting to round a null value."