From 79715765d0d3ecdfb314baabbec236e44c557839 Mon Sep 17 00:00:00 2001 From: Runa Dacino Date: Sat, 29 Jul 2023 14:18:05 +0200 Subject: [PATCH] tweak: Implements requested changes to ai init - In mob/living init, makes sure there is no pre-existing ai_holder before calling its init - In the initialize_ai_holder, double checks if we got a pre-existing ai_holder and properly GCs it if so - Furthermore, checks if the ai_holder_type was valid by checking if ai_holder is null, if so - logs a debug message and returns. --- code/modules/ai/ai_holder.dm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/code/modules/ai/ai_holder.dm b/code/modules/ai/ai_holder.dm index 347fff2b5cb..731ff4de0fd 100644 --- a/code/modules/ai/ai_holder.dm +++ b/code/modules/ai/ai_holder.dm @@ -15,7 +15,8 @@ var/ai_holder_type = null // Which ai_holder datum to give to the mob when initialized. If null, nothing happens. /mob/living/Initialize() - initialize_ai_holder() + if(!ai_holder) + initialize_ai_holder() return ..() /mob/living/Destroy() @@ -34,8 +35,15 @@ //Extracted from mob/living/Initialize() so that we may call it at any time after a mob was created /mob/living/proc/initialize_ai_holder() + if(ai_holder) //Making double sure we clean up and properly GC the original ai_holder + var/old_holder = ai_holder + ai_holder = null + qdel(old_holder) if(ai_holder_type) ai_holder = new ai_holder_type(src) + if(!ai_holder) + log_debug("[src] could not initialize ai_holder of type [ai_holder_type]") + return if(istype(src, /mob/living/carbon/human)) var/mob/living/carbon/human/H = src H.hud_used = new /datum/hud(H)