From 0a3edac8fbbde090ba3653df0cdfa1b31eec110f Mon Sep 17 00:00:00 2001 From: Azarak Date: Thu, 17 Dec 2020 10:42:49 +0100 Subject: [PATCH] Fixes GC for observers and new players, and tons of loose references to stuff that shouldnt be (#55563) I've done this on a signal because atom_hud is applied very loosely in some contexes, and the objects themselves dont have an easy way to track back into what huds they're affected by, so this seemed the best. Properly cleans up next_time_allowed, which was missing. Update: I discovered this is also an issue for a lot of simple mobs, such as slimes and bots and such. So fixing this is huge --- code/datums/hud.dm | 12 ++++++++++-- code/modules/mob/dead/observer/observer.dm | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/code/datums/hud.dm b/code/datums/hud.dm index 4b7fe138992..520fce789ad 100644 --- a/code/datums/hud.dm +++ b/code/datums/hud.dm @@ -51,11 +51,14 @@ GLOBAL_LIST_INIT(huds, list( GLOB.all_huds -= src return ..() -/datum/atom_hud/proc/remove_hud_from(mob/M) +/datum/atom_hud/proc/remove_hud_from(mob/M, absolute = FALSE) if(!M || !hudusers[M]) return - if (!--hudusers[M]) + if (absolute || !--hudusers[M]) + UnregisterSignal(M, COMSIG_PARENT_QDELETING) hudusers -= M + if(next_time_allowed[M]) + next_time_allowed -= M if(queued_to_see[M]) queued_to_see -= M else @@ -81,6 +84,7 @@ GLOBAL_LIST_INIT(huds, list( return if(!hudusers[M]) hudusers[M] = 1 + RegisterSignal(M, COMSIG_PARENT_QDELETING, .proc/unregister_mob) if(next_time_allowed[M] > world.time) if(!queued_to_see[M]) addtimer(CALLBACK(src, .proc/show_hud_images_after_cooldown, M), next_time_allowed[M] - world.time) @@ -92,6 +96,10 @@ GLOBAL_LIST_INIT(huds, list( else hudusers[M]++ +/datum/atom_hud/proc/unregister_mob(datum/source, force) + SIGNAL_HANDLER + remove_hud_from(source, TRUE) + /datum/atom_hud/proc/hide_single_atomhud_from(hud_user,hidden_atom) if(hudusers[hud_user]) remove_from_single_hud(hud_user,hidden_atom) diff --git a/code/modules/mob/dead/observer/observer.dm b/code/modules/mob/dead/observer/observer.dm index 6faab949603..68d245d8cdb 100644 --- a/code/modules/mob/dead/observer/observer.dm +++ b/code/modules/mob/dead/observer/observer.dm @@ -160,6 +160,9 @@ GLOBAL_VAR_INIT(observer_default_invisibility, INVISIBILITY_OBSERVER) addtimer(CALLBACK(src, /atom/proc/update_atom_colour), 10) /mob/dead/observer/Destroy() + if(data_huds_on) + remove_data_huds() + // Update our old body's medhud since we're abandoning it if(mind?.current) mind.current.med_hud_set_status()