From a61e8eaef5cf354733bc42ff71a09e46beda3611 Mon Sep 17 00:00:00 2001 From: Ben10Omintrix <138636438+Ben10Omintrix@users.noreply.github.com> Date: Tue, 16 Jul 2024 08:05:21 +0300 Subject: [PATCH] fixes a big harddel source (#83987) ## About The Pull Request this hard delete would happen everytime a player joins/observers the round. upon using the ref tracker i discovered this problem was caused by movable/screens not cleaning up after their owning huds if it gets deleted. i didnt weakref it was cause it meant id have to resolve it in so many places, but if weakrefing is preferable i will do it ![image](https://github.com/tgstation/tgstation/assets/138636438/d4b5465e-85b6-4e79-80a7-551684bdd831) ## Why It's Good For The Game fixes a hard delete --- code/_onclick/hud/new_player.dm | 3 +-- code/_onclick/hud/parallax/parallax.dm | 2 +- code/_onclick/hud/screen_objects.dm | 20 ++++++++++++++++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/code/_onclick/hud/new_player.dm b/code/_onclick/hud/new_player.dm index 5fa44b7f054..371341aec0b 100644 --- a/code/_onclick/hud/new_player.dm +++ b/code/_onclick/hud/new_player.dm @@ -63,8 +63,7 @@ ///Set the HUD in New, as lobby screens are made before Atoms are Initialized. /atom/movable/screen/lobby/New(loc, datum/hud/our_hud, ...) - if(our_hud) - hud = our_hud + set_new_hud(our_hud) return ..() ///Run sleeping actions after initialize diff --git a/code/_onclick/hud/parallax/parallax.dm b/code/_onclick/hud/parallax/parallax.dm index bcdcd0e74fe..0a3732e134f 100644 --- a/code/_onclick/hud/parallax/parallax.dm +++ b/code/_onclick/hud/parallax/parallax.dm @@ -275,7 +275,7 @@ INITIALIZE_IMMEDIATE(/atom/movable/screen/parallax_layer) . = ..() // Parallax layers are independant of hud, they care about client // Not doing this will just create a bunch of hard deletes - hud = null + set_new_hud(hud_owner = null) if(template) return diff --git a/code/_onclick/hud/screen_objects.dm b/code/_onclick/hud/screen_objects.dm index 8cc29740870..315efe48778 100644 --- a/code/_onclick/hud/screen_objects.dm +++ b/code/_onclick/hud/screen_objects.dm @@ -45,8 +45,9 @@ /atom/movable/screen/Initialize(mapload, datum/hud/hud_owner) . = ..() - if(hud_owner && istype(hud_owner)) - hud = hud_owner + if(isnull(hud_owner)) //some screens set their hud owners on /new, this prevents overriding them with null post atoms init + return + set_new_hud(hud_owner) /atom/movable/screen/Destroy() master_ref = null @@ -72,10 +73,25 @@ /atom/movable/screen/proc/component_click(atom/movable/screen/component_button/component, params) return +///setter used to set our new hud +/atom/movable/screen/proc/set_new_hud(datum/hud/hud_owner) + if(hud) + UnregisterSignal(hud, COMSIG_QDELETING) + if(isnull(hud_owner)) + hud = null + return + hud = hud_owner + RegisterSignal(hud, COMSIG_QDELETING, PROC_REF(on_hud_delete)) + /// Returns the mob this is being displayed to, if any /atom/movable/screen/proc/get_mob() return hud?.mymob +/atom/movable/screen/proc/on_hud_delete(datum/source) + SIGNAL_HANDLER + + set_new_hud(hud_owner = null) + /atom/movable/screen/text icon = null icon_state = null