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 <Batrochophreno@gmail.com>
This commit is contained in:
Batrachophreno
2025-08-14 14:45:00 +00:00
committed by GitHub
parent a38a1fc36a
commit 6662c8bd0f
2 changed files with 20 additions and 1 deletions
+7 -1
View File
@@ -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
@@ -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."