diff --git a/code/datums/components/xeno/ai_behavior_overrides/base_override_behavior.dm b/code/datums/components/xeno/ai_behavior_overrides/base_override_behavior.dm index 9e4a25e71c..9e3e0a1093 100644 --- a/code/datums/components/xeno/ai_behavior_overrides/base_override_behavior.dm +++ b/code/datums/components/xeno/ai_behavior_overrides/base_override_behavior.dm @@ -36,6 +36,9 @@ GLOBAL_LIST_EMPTY(all_ai_behavior_overrides) game_master.images -= behavior_image QDEL_NULL(behavior_image) + + for(var/assigned_xeno in currently_assigned) + UnregisterSignal(assigned_xeno, COMSIG_PARENT_QDELETING) currently_assigned = null . = ..() @@ -54,6 +57,14 @@ GLOBAL_LIST_EMPTY(all_ai_behavior_overrides) /datum/component/ai_behavior_override/proc/process_override_behavior(mob/living/carbon/xenomorph/processing_xeno, delta_time) SHOULD_NOT_SLEEP(TRUE) + RegisterSignal(processing_xeno, COMSIG_PARENT_QDELETING, PROC_REF(remove_from_queue), TRUE) currently_assigned |= processing_xeno return TRUE + +/datum/component/ai_behavior_override/proc/remove_from_queue(mob/removed_xeno) + SIGNAL_HANDLER + if(currently_assigned) + currently_assigned -= removed_xeno + + UnregisterSignal(removed_xeno, COMSIG_PARENT_QDELETING) diff --git a/code/modules/mob/living/carbon/xenomorph/Xenomorph.dm b/code/modules/mob/living/carbon/xenomorph/Xenomorph.dm index 6fa56f7888..c916bef3da 100644 --- a/code/modules/mob/living/carbon/xenomorph/Xenomorph.dm +++ b/code/modules/mob/living/carbon/xenomorph/Xenomorph.dm @@ -725,10 +725,6 @@ if(hardcore) attack_log?.Cut() // Completely clear out attack_log to limit mem usage if we fail to delete - for(var/datum/component/ai_behavior_override/override in GLOB.all_ai_behavior_overrides) - if(override.currently_assigned) - override.currently_assigned -= src - . = ..() // Everything below fits the "we have to clear by principle it but i dont wanna break stuff" bill diff --git a/code/modules/mob/living/carbon/xenomorph/ai/xeno_ai.dm b/code/modules/mob/living/carbon/xenomorph/ai/xeno_ai.dm index 34407707f8..66c9c132b7 100644 --- a/code/modules/mob/living/carbon/xenomorph/ai/xeno_ai.dm +++ b/code/modules/mob/living/carbon/xenomorph/ai/xeno_ai.dm @@ -235,8 +235,7 @@ var/validity = cycled_override.check_behavior_validity(src, distance) if(!validity || distance >= shortest_distance) - if(cycled_override.currently_assigned) - cycled_override.currently_assigned -= src + cycled_override.remove_from_queue(src) continue shortest_distance = distance