diff --git a/code/modules/modular_computers/computers/modular_computer/core.dm b/code/modules/modular_computers/computers/modular_computer/core.dm index 4ec873f74ec..66dc060f723 100644 --- a/code/modules/modular_computers/computers/modular_computer/core.dm +++ b/code/modules/modular_computers/computers/modular_computer/core.dm @@ -383,7 +383,7 @@ to_chat(user, SPAN_WARNING("\The [src]'s screen displays, \"I/O ERROR - Unable to run [prog]\".")) return - P.computer = src + P.set_computer(src) if(!P.is_supported_by_hardware(hardware_flag, TRUE, user)) return @@ -501,7 +501,7 @@ if(QDELETED(S)) return - S.computer = src + S.set_computer(src) if(!S.is_supported_by_hardware(hardware_flag, 1, user)) return diff --git a/code/modules/modular_computers/file_system/program.dm b/code/modules/modular_computers/file_system/program.dm index db881785784..28eb2d8a6e1 100644 --- a/code/modules/modular_computers/file_system/program.dm +++ b/code/modules/modular_computers/file_system/program.dm @@ -26,7 +26,11 @@ ABSTRACT_TYPE(/datum/computer_file/program) /// PROGRAM_STATE_KILLED or PROGRAM_STATE_BACKGROUND or PROGRAM_STATE_ACTIVE - specifies whether this program is running. var/program_state = PROGRAM_STATE_KILLED - /// Device that runs this program. + /** + * The device that runs this program + * + * **Only supported way to set this is by calling set_computer()** + */ var/obj/item/modular_computer/computer /// Short description of this program's function. @@ -86,13 +90,13 @@ ABSTRACT_TYPE(/datum/computer_file/program) var/datum/nano_module/NM // If the program uses NanoModule, put it here and it will be automagically opened. Otherwise implement ui_interact. var/nanomodule_path // Path to nanomodule, make sure to set this if implementing new program. -/datum/computer_file/program/New(var/obj/item/modular_computer/comp) +/datum/computer_file/program/New(obj/item/modular_computer/comp) ..() if(comp) if(comp == "Compless") // we're software in the air, don't need a computer return else if(istype(comp)) - computer = comp + set_computer(comp) else crash_with("Comp was of the wrong type for [src.filename]") else @@ -102,7 +106,7 @@ ABSTRACT_TYPE(/datum/computer_file/program) if(!QDELETED(computer)) computer.idle_threads -= src computer.enabled_services -= src - computer = null + set_computer(null) . = ..() GC_TEMPORARY_HARDDEL @@ -139,6 +143,39 @@ ABSTRACT_TYPE(/datum/computer_file/program) temp.usage_flags = usage_flags return temp +/** + * Sets the computer this program is running on + * + * * computer - The computer to set this program to, or `null` to remove it + */ +/datum/computer_file/program/proc/set_computer(obj/item/modular_computer/computer) + SHOULD_NOT_SLEEP(TRUE) + + //Not setting something already being deleted + if(istype(computer) && QDELETED(computer)) + return + + //It's already the same + if(src.computer == computer) + return + + //Stop listening for the old computer + if(istype(src.computer)) + UnregisterSignal(src.computer, COMSIG_QDELETING) + + src.computer = computer + + //Start listening for the new computer, if it's one + if(istype(computer)) + RegisterSignal(computer, COMSIG_QDELETING, PROC_REF(on_computer_deleted)) + +/** + * Handles signal when the computer we are referencing is deleted + */ +/datum/computer_file/program/proc/on_computer_deleted() + SIGNAL_HANDLER + qdel(src) + // Relays icon update to the computer. /datum/computer_file/program/proc/update_computer_icon() if(computer) diff --git a/html/changelogs/fluffyghost-helpdeleteprograms.yml b/html/changelogs/fluffyghost-helpdeleteprograms.yml new file mode 100644 index 00000000000..e27bf9c9beb --- /dev/null +++ b/html/changelogs/fluffyghost-helpdeleteprograms.yml @@ -0,0 +1,58 @@ +################################ +# Example Changelog File +# +# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb. +# +# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.) +# When it is, any changes listed below will disappear. +# +# Valid Prefixes: +# bugfix +# - (fixes bugs) +# wip +# - (work in progress) +# qol +# - (quality of life) +# soundadd +# - (adds a sound) +# sounddel +# - (removes a sound) +# rscadd +# - (adds a feature) +# rscdel +# - (removes a feature) +# imageadd +# - (adds an image or sprite) +# imagedel +# - (removes an image or sprite) +# spellcheck +# - (fixes spelling or grammar) +# experiment +# - (experimental change) +# balance +# - (balance changes) +# code_imp +# - (misc internal code change) +# refactor +# - (refactors code) +# config +# - (makes a change to the config files) +# admin +# - (makes changes to administrator tools) +# server +# - (miscellaneous changes to server) +################################# + +# Your name. +author: FluffyGhost + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, this gets changed to [] after reading. Just remove the brackets when you add new shit. +# Please surround your changes in double quotes ("). It works without them, but if you use certain characters it screws up compiling. The quotes will not show up in the changelog. +changes: + - code_imp: "Hopefully helps fixes some hard references being left when deleting modular computers, in their programs."