From 8386e9cdef9aca8ed40f276069728af97683fc5f Mon Sep 17 00:00:00 2001 From: Farie82 Date: Wed, 19 Oct 2022 05:52:35 +0200 Subject: [PATCH] Fixes waterpacks and friends not GCing (#19269) Move nozzles to Initialize Makes reagents not hold a reference to their atom when they get destroyed --- .../objects/items/weapons/extinguisher.dm | 9 ++-- .../objects/items/weapons/tanks/watertank.dm | 42 ++++++++++--------- code/modules/reagents/chemistry/holder.dm | 1 + code/modules/reagents/reagent_containers.dm | 3 +- 4 files changed, 31 insertions(+), 24 deletions(-) diff --git a/code/game/objects/items/weapons/extinguisher.dm b/code/game/objects/items/weapons/extinguisher.dm index c53f52daee7..ed89ab2b92c 100644 --- a/code/game/objects/items/weapons/extinguisher.dm +++ b/code/game/objects/items/weapons/extinguisher.dm @@ -45,10 +45,11 @@ . += "The safety is [safety ? "on" : "off"]." -/obj/item/extinguisher/New() - ..() - create_reagents(max_water) - reagents.add_reagent("water", max_water) +/obj/item/extinguisher/Initialize(mapload) + . = ..() + if(!reagents) + create_reagents(max_water) + reagents.add_reagent("water", max_water) /obj/item/extinguisher/attack_self(mob/user as mob) safety = !safety diff --git a/code/game/objects/items/weapons/tanks/watertank.dm b/code/game/objects/items/weapons/tanks/watertank.dm index 7a157f5c79c..0886a43d546 100644 --- a/code/game/objects/items/weapons/tanks/watertank.dm +++ b/code/game/objects/items/weapons/tanks/watertank.dm @@ -128,16 +128,16 @@ var/obj/item/watertank/tank -/obj/item/reagent_containers/spray/mister/New(parent_tank) - ..() - if(check_tank_exists(parent_tank, src)) - tank = parent_tank - reagents = tank.reagents //This mister is really just a proxy for the tank's reagents - loc = tank - return +/obj/item/reagent_containers/spray/mister/Initialize(mapload) + if(!check_tank_exists(loc, src)) + return INITIALIZE_HINT_QDEL + tank = loc + reagents = tank.reagents //This mister is really just a proxy for the tank's reagents + return ..() /obj/item/reagent_containers/spray/mister/Destroy() tank = null + reagents = null // Unset, this is the tanks reagents return ..() /obj/item/reagent_containers/spray/mister/dropped(mob/user as mob) @@ -151,11 +151,9 @@ /proc/check_tank_exists(parent_tank, mob/living/carbon/human/M, obj/O) if(!parent_tank || !istype(parent_tank, /obj/item/watertank)) //To avoid weird issues from admin spawns - M.unEquip(O) - qdel(0) - return 0 + return FALSE else - return 1 + return TRUE /obj/item/reagent_containers/spray/mister/Move() ..() @@ -239,14 +237,20 @@ var/metal_synthesis_cooldown = 0 var/nanofrost_cooldown = 0 -/obj/item/extinguisher/mini/nozzle/New(parent_tank) - . = ..() - if(check_tank_exists(parent_tank, src)) - tank = parent_tank - reagents = tank.reagents - max_water = tank.volume - loc = tank - return +/obj/item/extinguisher/mini/nozzle/Initialize(mapload) + if(!check_tank_exists(loc, src)) + return INITIALIZE_HINT_QDEL + + tank = loc + reagents = tank.reagents + max_water = tank.volume + + return ..() + +/obj/item/extinguisher/mini/nozzle/Destroy() + tank = null + reagents = null // Unset, this is the tanks reagents + return ..() /obj/item/extinguisher/mini/nozzle/Move() ..() diff --git a/code/modules/reagents/chemistry/holder.dm b/code/modules/reagents/chemistry/holder.dm index 02d514b6c9f..818ec90c848 100644 --- a/code/modules/reagents/chemistry/holder.dm +++ b/code/modules/reagents/chemistry/holder.dm @@ -864,3 +864,4 @@ addiction_list = null if(my_atom && my_atom.reagents == src) my_atom.reagents = null + my_atom = null diff --git a/code/modules/reagents/reagent_containers.dm b/code/modules/reagents/reagent_containers.dm index 25c9305231d..4cded6b3cfe 100644 --- a/code/modules/reagents/reagent_containers.dm +++ b/code/modules/reagents/reagent_containers.dm @@ -45,7 +45,8 @@ /obj/item/reagent_containers/Initialize(mapload) . = ..() - create_reagents(volume, temperature_min, temperature_max) + if(!reagents) // Some subtypes create their own reagents + create_reagents(volume, temperature_min, temperature_max) if(!possible_transfer_amounts) verbs -= /obj/item/reagent_containers/verb/set_APTFT if(spawned_disease)