From 2180c4c1fee7981cb9d1e4a5be1fe0bcc0f88764 Mon Sep 17 00:00:00 2001 From: kevinz000 <2003111+kevinz000@users.noreply.github.com> Date: Sun, 12 Nov 2017 15:58:53 -0800 Subject: [PATCH] Checks for nulls in weakrefs --- code/datums/weakrefs.dm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 code/datums/weakrefs.dm diff --git a/code/datums/weakrefs.dm b/code/datums/weakrefs.dm new file mode 100644 index 0000000000..8af2491451 --- /dev/null +++ b/code/datums/weakrefs.dm @@ -0,0 +1,19 @@ + +/proc/WEAKREF(datum/input) + if(istype(input) && !QDELETED(input)) + if(!input.weak_reference) + input.weak_reference = new /datum/weakref(input) + return input.weak_reference + +/datum/weakref + var/reference + +/datum/weakref/New(datum/thing) + reference = REF(thing) + +/datum/weakref/Destroy() + return QDEL_HINT_LETMELIVE //Let BYOND autoGC thiswhen nothing is using it anymore. + +/datum/weakref/proc/resolve() + var/datum/D = locate(reference) + return (!QDELETED(D) && D.weak_reference == src) ? D : null