From 277790a6303b68e911e8364158aee50ed582ee4f Mon Sep 17 00:00:00 2001 From: Lohikar Date: Sat, 20 May 2017 06:24:47 -0500 Subject: [PATCH] (Hopefully) Fix Mind GC Issues (#2301) Should fix weirdness with mob GC such as ghosts jumping to their deleted bodies, observers failing to GC, and mobs with minds not GCing in general. changes: Mob cleanup relating to the mob has been moved to the mind. On deletion a mob will now null out the current and original fields in the mind, if they pointed to it. --- code/datums/mind.dm | 9 +++++++++ code/modules/mob/mob.dm | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/code/datums/mind.dm b/code/datums/mind.dm index d11ab68f21b..7a96a1ed48d 100644 --- a/code/datums/mind.dm +++ b/code/datums/mind.dm @@ -65,10 +65,19 @@ //put this here for easier tracking ingame var/datum/money_account/initial_account + /datum/mind/New(var/key) src.key = key ..() +/datum/mind/proc/handle_mob_deletion(mob/living/deleted_mob) + if (current == deleted_mob) + current.spellremove() + current = null + + if (original == deleted_mob) + original = null + /datum/mind/proc/transfer_to(mob/living/new_character) if(!istype(new_character)) world.log << "## DEBUG: transfer_to(): Some idiot has tried to transfer_to() a non mob/living mob. Please inform Carn" diff --git a/code/modules/mob/mob.dm b/code/modules/mob/mob.dm index 3aa6865b7bc..f514caa4c64 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -11,8 +11,8 @@ for(var/atom/movable/AM in client.screen) qdel(AM) client.screen = list() - if(mind && mind.current == src) - spellremove(src) + if (mind) + mind.handle_mob_deletion(src) for(var/infection in viruses) qdel(infection) viruses.Cut()