Add weakref support to qdel (#56171)

qdel() should allow usage of weakrefs to avoid harddels on long duration qdel_in usage
This commit is contained in:
spookydonut
2021-01-16 11:30:40 -05:00
committed by GitHub
parent cc98bcd019
commit 3b3150aa4a
3 changed files with 9 additions and 3 deletions
+7 -1
View File
@@ -284,15 +284,21 @@ SUBSYSTEM_DEF(garbage)
///
/// Datums passed to this will be given a chance to clean up references to allow the GC to collect them.
/proc/qdel(datum/D, force=FALSE, ...)
if(isweakref(D))
var/datum/weakref/weakref = D
D = weakref.resolve()
if(!D)
return
if(!istype(D))
del(D)
return
var/datum/qdel_item/I = SSgarbage.items[D.type]
if (!I)
I = SSgarbage.items[D.type] = new /datum/qdel_item(D.type)
I.qdels++
if(isnull(D.gc_destroyed))
if (SEND_SIGNAL(D, COMSIG_PARENT_PREQDELETED, force)) // Give the components a chance to prevent their parent from being deleted
return
+1 -1
View File
@@ -180,7 +180,7 @@
QDEL_IN(colour, 11)
doomslayer = victim
RegisterSignal(src, COMSIG_PARENT_QDELETING, .proc/end_blood_frenzy)
QDEL_IN(src, duration)
QDEL_IN(WEAKREF(src), duration)
/obj/effect/mine/pickup/bloodbath/proc/end_blood_frenzy()
if(doomslayer)
+1 -1
View File
@@ -87,7 +87,7 @@
add_overlay("hatch")
add_overlay("legs_retracted")
addtimer(CALLBACK(src, .proc/startUp), 50)
QDEL_IN(src, 8 MINUTES) //Self-destruct after 8 min
QDEL_IN(WEAKREF(src), 8 MINUTES) //Self-destruct after 8 min
SSeconomy.market_crashing = TRUE