From ed0999e4eabcbe8513eb1ee1d5851ebd15bbe764 Mon Sep 17 00:00:00 2001 From: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Date: Tue, 22 Aug 2023 19:32:30 -0700 Subject: [PATCH] Adds error on qdeling callback, fixes errors this causes (#77850) ## About The Pull Request You shouldn't ever qdel a callback. If you don't want to own it free your ref (remove it from a list/set it to null). When all refs are cleared it'll get cleaned up by byond itself --- code/_onclick/hud/radial.dm | 2 +- .../controllers/subsystem/circuit_component.dm | 3 --- code/controllers/subsystem/throwing.dm | 3 +-- code/datums/callback.dm | 15 +++++++++++++++ code/datums/cinematics/_cinematic.dm | 2 +- code/datums/components/action_item_overlay.dm | 2 +- code/datums/components/anti_magic.dm | 4 ++-- code/datums/components/bullet_intercepting.dm | 2 +- code/datums/components/cleaner.dm | 6 ++---- code/datums/components/effect_remover.dm | 2 +- code/datums/components/food/edible.dm | 6 +++--- code/datums/components/food/golem_food.dm | 2 +- code/datums/components/ghost_direct_control.dm | 4 ++-- code/datums/components/healing_touch.dm | 2 +- .../components/health_scaling_effects.dm | 2 +- code/datums/components/jetpack.dm | 2 +- code/datums/components/mind_linker.dm | 2 +- code/datums/components/rotation.dm | 2 +- code/datums/components/shielded.dm | 2 +- code/datums/components/singularity.dm | 2 +- code/datums/components/spin2win.dm | 4 ++-- code/datums/components/swabbing.dm | 4 ++-- .../components/takes_reagent_appearance.dm | 4 ++-- code/datums/components/tippable.dm | 12 ++++-------- .../components/toggle_attached_clothing.dm | 7 ++++--- code/datums/helper_datums/events.dm | 18 ++++++------------ code/modules/events/wizard/greentext.dm | 2 +- .../modules/mob/living/basic/pets/dog/corgi.dm | 2 +- .../security_levels/keycard_authentication.dm | 8 ++++---- 29 files changed, 64 insertions(+), 64 deletions(-) diff --git a/code/_onclick/hud/radial.dm b/code/_onclick/hud/radial.dm index 36bc7dbd720..5bc75d85f47 100644 --- a/code/_onclick/hud/radial.dm +++ b/code/_onclick/hud/radial.dm @@ -337,7 +337,7 @@ GLOBAL_LIST_EMPTY(radial_menus) /datum/radial_menu/Destroy() Reset() hide() - QDEL_NULL(custom_check_callback) + custom_check_callback = null . = ..() /* diff --git a/code/controllers/subsystem/circuit_component.dm b/code/controllers/subsystem/circuit_component.dm index ceea6b7e44e..3ef1be5a3aa 100644 --- a/code/controllers/subsystem/circuit_component.dm +++ b/code/controllers/subsystem/circuit_component.dm @@ -28,8 +28,6 @@ SUBSYSTEM_DEF(circuit_component) to_call.user = null to_call.InvokeAsync() - qdel(to_call) - if(MC_TICK_CHECK) return @@ -76,7 +74,6 @@ SUBSYSTEM_DEF(circuit_component) instant_run_currentrun.Cut(1,2) to_call.user = null to_call.InvokeAsync(received_inputs) - qdel(to_call) if(length(instant_run_stack)) instant_run_callbacks_to_run = pop(instant_run_stack) diff --git a/code/controllers/subsystem/throwing.dm b/code/controllers/subsystem/throwing.dm index 4bb21be2c0a..a316dbf2f1c 100644 --- a/code/controllers/subsystem/throwing.dm +++ b/code/controllers/subsystem/throwing.dm @@ -115,8 +115,7 @@ SUBSYSTEM_DEF(throwing) thrownthing = null thrower = null initial_target = null - if(callback) - QDEL_NULL(callback) //It stores a reference to the thrownthing, its source. Let's clean that. + callback = null return ..() ///Defines the datum behavior on the thrownthing's qdeletion event. diff --git a/code/datums/callback.dm b/code/datums/callback.dm index a51639d0b9b..026762d58f7 100644 --- a/code/datums/callback.dm +++ b/code/datums/callback.dm @@ -68,6 +68,21 @@ if(usr) user = WEAKREF(usr) +/** + * Qdel a callback datum + * This is not allowed and will stack trace. callback datums are structs, if they are referenced they exist + * + * Arguments + * * force set to true to force the deletion to be allowed. + * * ... an optional list of extra arguments to pass to the proc + */ +/datum/callback/Destroy(force=FALSE, ...) + SHOULD_CALL_PARENT(FALSE) + if (force) + return ..() + stack_trace("Callbacks can not be qdeleted. If they are referenced, they must exist. ([object == GLOBAL_PROC ? GLOBAL_PROC : object.type] [delegate])") + return QDEL_HINT_LETMELIVE + /** * Invoke this callback * diff --git a/code/datums/cinematics/_cinematic.dm b/code/datums/cinematics/_cinematic.dm index 68b288e1227..36b15998bf1 100644 --- a/code/datums/cinematics/_cinematic.dm +++ b/code/datums/cinematics/_cinematic.dm @@ -52,7 +52,7 @@ /datum/cinematic/Destroy() QDEL_NULL(screen) - QDEL_NULL(special_callback) + special_callback = null watching.Cut() locked.Cut() return ..() diff --git a/code/datums/components/action_item_overlay.dm b/code/datums/components/action_item_overlay.dm index 221fc38775c..e7e567cde36 100644 --- a/code/datums/components/action_item_overlay.dm +++ b/code/datums/components/action_item_overlay.dm @@ -26,7 +26,7 @@ /datum/component/action_item_overlay/Destroy(force, silent) item_ref = null - QDEL_NULL(item_callback) + item_callback = null item_appearance = null return ..() diff --git a/code/datums/components/anti_magic.dm b/code/datums/components/anti_magic.dm index e5e78fecf78..d3d53237777 100644 --- a/code/datums/components/anti_magic.dm +++ b/code/datums/components/anti_magic.dm @@ -56,8 +56,8 @@ src.expiration = expiration /datum/component/anti_magic/Destroy(force, silent) - QDEL_NULL(drain_antimagic) - QDEL_NULL(expiration) + drain_antimagic = null + expiration = null return ..() /datum/component/anti_magic/proc/register_antimagic_signals(datum/on_what) diff --git a/code/datums/components/bullet_intercepting.dm b/code/datums/components/bullet_intercepting.dm index 151f748e8aa..ffae74f381d 100644 --- a/code/datums/components/bullet_intercepting.dm +++ b/code/datums/components/bullet_intercepting.dm @@ -26,7 +26,7 @@ RegisterSignal(parent, COMSIG_ITEM_PRE_UNEQUIP, PROC_REF(on_unequipped)) /datum/component/bullet_intercepting/Destroy(force, silent) - QDEL_NULL(on_intercepted) + on_intercepted = null return ..() /// Called when item changes slots, check if we're in a valid location to take bullets diff --git a/code/datums/components/cleaner.dm b/code/datums/components/cleaner.dm index 3afdc8bf102..ccad85f43f1 100644 --- a/code/datums/components/cleaner.dm +++ b/code/datums/components/cleaner.dm @@ -30,10 +30,8 @@ src.on_cleaned_callback = on_cleaned_callback /datum/component/cleaner/Destroy(force, silent) - if(pre_clean_callback) - QDEL_NULL(pre_clean_callback) - if(on_cleaned_callback) - QDEL_NULL(on_cleaned_callback) + pre_clean_callback = null + on_cleaned_callback = null return ..() /datum/component/cleaner/RegisterWithParent() diff --git a/code/datums/components/effect_remover.dm b/code/datums/components/effect_remover.dm index 8a117961fd2..7f1f437eddf 100644 --- a/code/datums/components/effect_remover.dm +++ b/code/datums/components/effect_remover.dm @@ -42,7 +42,7 @@ src.time_to_remove = time_to_remove /datum/component/effect_remover/Destroy(force, silent) - QDEL_NULL(on_clear_callback) + on_clear_callback = null return ..() /datum/component/effect_remover/RegisterWithParent() diff --git a/code/datums/components/food/edible.dm b/code/datums/components/food/edible.dm index e8c9a37c99f..9a2ad6973f8 100644 --- a/code/datums/components/food/edible.dm +++ b/code/datums/components/food/edible.dm @@ -187,9 +187,9 @@ Behavior that's still missing from this component that original food items had t setup_initial_reagents(initial_reagents) /datum/component/edible/Destroy(force, silent) - QDEL_NULL(after_eat) - QDEL_NULL(on_consume) - QDEL_NULL(check_liked) + after_eat = null + on_consume = null + check_liked = null return ..() /// Sets up the initial reagents of the food. diff --git a/code/datums/components/food/golem_food.dm b/code/datums/components/food/golem_food.dm index e6b6fbbf4c3..01e44a5958c 100644 --- a/code/datums/components/food/golem_food.dm +++ b/code/datums/components/food/golem_food.dm @@ -31,7 +31,7 @@ /datum/component/golem_food/Destroy(force, silent) QDEL_NULL(golem_snack) - QDEL_NULL(extra_validation) + extra_validation = null return ..() /// Attempt to feed this item to golem diff --git a/code/datums/components/ghost_direct_control.dm b/code/datums/components/ghost_direct_control.dm index 6ff22b4266a..c4d08380db1 100644 --- a/code/datums/components/ghost_direct_control.dm +++ b/code/datums/components/ghost_direct_control.dm @@ -48,8 +48,8 @@ return ..() /datum/component/ghost_direct_control/Destroy(force, silent) - QDEL_NULL(extra_control_checks) - QDEL_NULL(after_assumed_control) + extra_control_checks = null + after_assumed_control = null var/mob/mob_parent = parent var/list/spawners = GLOB.joinable_mobs[format_text("[initial(mob_parent.name)]")] diff --git a/code/datums/components/healing_touch.dm b/code/datums/components/healing_touch.dm index 723c6cf2d80..4b953fc6289 100644 --- a/code/datums/components/healing_touch.dm +++ b/code/datums/components/healing_touch.dm @@ -71,7 +71,7 @@ return ..() /datum/component/healing_touch/Destroy(force, silent) - QDEL_NULL(extra_checks) + extra_checks = null return ..() /// Validate our target, and interrupt the attack chain to start healing it if it is allowed diff --git a/code/datums/components/health_scaling_effects.dm b/code/datums/components/health_scaling_effects.dm index ecfb9ceb1e5..140a60ea962 100644 --- a/code/datums/components/health_scaling_effects.dm +++ b/code/datums/components/health_scaling_effects.dm @@ -54,7 +54,7 @@ return ..() /datum/component/health_scaling_effects/Destroy(force, silent) - QDEL_NULL(additional_status_callback) + additional_status_callback = null return ..() /// Called when mob health changes, recalculates the ratio between maximum and minimum diff --git a/code/datums/components/jetpack.dm b/code/datums/components/jetpack.dm index 902a4a3430a..dbc22d4ce5a 100644 --- a/code/datums/components/jetpack.dm +++ b/code/datums/components/jetpack.dm @@ -66,7 +66,7 @@ /datum/component/jetpack/Destroy() if(trail) QDEL_NULL(trail) - QDEL_NULL(check_on_move) + check_on_move = null return ..() /datum/component/jetpack/proc/setup_trail(mob/user) diff --git a/code/datums/components/mind_linker.dm b/code/datums/components/mind_linker.dm index 9f723a636ed..050a9762f07 100644 --- a/code/datums/components/mind_linker.dm +++ b/code/datums/components/mind_linker.dm @@ -64,7 +64,7 @@ unlink_mob(remaining_mob) linked_mobs.Cut() QDEL_NULL(master_speech) - QDEL_NULL(post_unlink_callback) + post_unlink_callback = null return ..() /datum/component/mind_linker/RegisterWithParent() diff --git a/code/datums/components/rotation.dm b/code/datums/components/rotation.dm index dc009ffbf89..e47a47f595d 100644 --- a/code/datums/components/rotation.dm +++ b/code/datums/components/rotation.dm @@ -45,7 +45,7 @@ . = ..() /datum/component/simple_rotation/Destroy() - QDEL_NULL(AfterRotation) + AfterRotation = null //Signals + verbs removed via UnRegister . = ..() diff --git a/code/datums/components/shielded.dm b/code/datums/components/shielded.dm index eeca72b5815..b33f3d986fd 100644 --- a/code/datums/components/shielded.dm +++ b/code/datums/components/shielded.dm @@ -62,7 +62,7 @@ UnregisterSignal(wearer, COMSIG_ATOM_UPDATE_OVERLAYS) wearer.update_appearance(UPDATE_ICON) wearer = null - QDEL_NULL(on_hit_effects) + on_hit_effects = null return ..() /datum/component/shielded/RegisterWithParent() diff --git a/code/datums/components/singularity.dm b/code/datums/components/singularity.dm index 043be3e50c0..75fd4fd0abc 100644 --- a/code/datums/components/singularity.dm +++ b/code/datums/components/singularity.dm @@ -110,7 +110,7 @@ /datum/component/singularity/Destroy(force, silent) GLOB.singularities -= src - QDEL_NULL(consume_callback) + consume_callback = null target = null return ..() diff --git a/code/datums/components/spin2win.dm b/code/datums/components/spin2win.dm index c1c935509f9..19eebfed509 100644 --- a/code/datums/components/spin2win.dm +++ b/code/datums/components/spin2win.dm @@ -37,8 +37,8 @@ src.end_spin_message = end_spin_message /datum/component/spin2win/Destroy(force, silent) - QDEL_NULL(on_spin_callback) - QDEL_NULL(on_unspin_callback) + on_spin_callback = null + on_unspin_callback = null return ..() /datum/component/spin2win/RegisterWithParent() diff --git a/code/datums/components/swabbing.dm b/code/datums/components/swabbing.dm index 0fb13e6055d..056f97cf98b 100644 --- a/code/datums/components/swabbing.dm +++ b/code/datums/components/swabbing.dm @@ -36,8 +36,8 @@ This component is used in vat growing to swab for microbiological samples which . = ..() for(var/swabbed in swabbed_items) qdel(swabbed) - QDEL_NULL(update_icons) - QDEL_NULL(update_overlays) + update_icons = null + update_overlays = null ///Changes examine based on your sample diff --git a/code/datums/components/takes_reagent_appearance.dm b/code/datums/components/takes_reagent_appearance.dm index 0d5730fc80d..59bd17adb87 100644 --- a/code/datums/components/takes_reagent_appearance.dm +++ b/code/datums/components/takes_reagent_appearance.dm @@ -44,8 +44,8 @@ src.base_container_type = base_container_type || parent.type /datum/component/takes_reagent_appearance/Destroy() - QDEL_NULL(on_icon_changed) - QDEL_NULL(on_icon_reset) + on_icon_changed = null + on_icon_reset = null return ..() /datum/component/takes_reagent_appearance/RegisterWithParent() diff --git a/code/datums/components/tippable.dm b/code/datums/components/tippable.dm index e4ecd8a91f4..eafb2345818 100644 --- a/code/datums/components/tippable.dm +++ b/code/datums/components/tippable.dm @@ -63,14 +63,10 @@ UnregisterSignal(parent, COMSIG_ATOM_ATTACK_HAND_SECONDARY) /datum/component/tippable/Destroy() - if(pre_tipped_callback) - QDEL_NULL(pre_tipped_callback) - if(post_tipped_callback) - QDEL_NULL(post_tipped_callback) - if(post_untipped_callback) - QDEL_NULL(post_untipped_callback) - if(roleplay_callback) - QDEL_NULL(roleplay_callback) + pre_tipped_callback = null + post_tipped_callback = null + post_untipped_callback = null + roleplay_callback = null return ..() /** diff --git a/code/datums/components/toggle_attached_clothing.dm b/code/datums/components/toggle_attached_clothing.dm index 55387c9e58c..805b289e618 100644 --- a/code/datums/components/toggle_attached_clothing.dm +++ b/code/datums/components/toggle_attached_clothing.dm @@ -82,9 +82,10 @@ unequip_deployable() QDEL_NULL(deployable) QDEL_NULL(toggle_action) - QDEL_NULL(on_created) - QDEL_NULL(on_deployed) - QDEL_NULL(on_removed) + pre_creation_check = null + on_created = null + on_deployed = null + on_removed = null return ..() /// Toggle deployable when the UI button is clicked diff --git a/code/datums/helper_datums/events.dm b/code/datums/helper_datums/events.dm index 512b5097c07..42750c752f1 100644 --- a/code/datums/helper_datums/events.dm +++ b/code/datums/helper_datums/events.dm @@ -11,9 +11,6 @@ events = new /datum/events/Destroy() - for(var/elist in events) - for(var/e in events[elist]) - qdel(e) events = null return ..() @@ -23,8 +20,8 @@ return TRUE return FALSE -// Arguments: event_type as text, proc_holder as datum, proc_name as text -// Returns: New event, null on error. +/// Arguments: event_type as text, proc_holder as datum, proc_name as text +/// Returns: New event, null on error. /datum/events/proc/addEvent(event_type as text, datum/callback/cb) if(!event_type || !cb) return @@ -33,23 +30,20 @@ event += cb return cb -// Arguments: event_type as text, any number of additional arguments to pass to event handler -// Returns: null +/// Arguments: event_type as text, any number of additional arguments to pass to event handler +/// Returns: null /datum/events/proc/fireEvent(eventName, ...) - var/list/event = LAZYACCESS(events,eventName) if(istype(event)) for(var/E in event) var/datum/callback/cb = E cb.InvokeAsync(arglist(args.Copy(2))) -// Arguments: event_type as text, E as /datum/event -// Returns: TRUE if event cleared, FALSE on error - +/// Arguments: event_type as text, E as /datum/event +/// Returns: TRUE if event cleared, FALSE on error /datum/events/proc/clearEvent(event_type as text, datum/callback/cb) if(!event_type || !cb) return FALSE var/list/event = LAZYACCESS(events,event_type) event -= cb - qdel(cb) return TRUE diff --git a/code/modules/events/wizard/greentext.dm b/code/modules/events/wizard/greentext.dm index bdb053365df..6b4b8be0ff8 100644 --- a/code/modules/events/wizard/greentext.dm +++ b/code/modules/events/wizard/greentext.dm @@ -67,7 +67,7 @@ /obj/item/greentext/Destroy(force) LAZYREMOVE(SSticker.round_end_events, roundend_callback) - QDEL_NULL(roundend_callback) //This ought to free the callback datum, and prevent us from harddeling + roundend_callback = null //This ought to free the callback datum, and prevent us from harddeling if(LAZYLEN(color_altered_mobs)) INVOKE_ASYNC(src, PROC_REF(release_victims)) return ..() diff --git a/code/modules/mob/living/basic/pets/dog/corgi.dm b/code/modules/mob/living/basic/pets/dog/corgi.dm index 763335fff50..d072a1c897e 100644 --- a/code/modules/mob/living/basic/pets/dog/corgi.dm +++ b/code/modules/mob/living/basic/pets/dog/corgi.dm @@ -372,7 +372,7 @@ /mob/living/basic/pet/dog/corgi/ian/Destroy() LAZYREMOVE(SSticker.round_end_events, i_will_survive) //cleanup the survival callback - QDEL_NULL(i_will_survive) + i_will_survive = null return ..() /mob/living/basic/pet/dog/corgi/ian/death() diff --git a/code/modules/security_levels/keycard_authentication.dm b/code/modules/security_levels/keycard_authentication.dm index 1eabf6fdc0c..66bf8b3bc93 100644 --- a/code/modules/security_levels/keycard_authentication.dm +++ b/code/modules/security_levels/keycard_authentication.dm @@ -15,7 +15,7 @@ GLOBAL_DATUM_INIT(keycard_events, /datum/events, new) req_access = list(ACCESS_KEYCARD_AUTH) resistance_flags = INDESTRUCTIBLE | LAVA_PROOF | FIRE_PROOF | UNACIDABLE | ACID_PROOF - var/datum/callback/ev + var/datum/callback/activated var/event = "" var/obj/machinery/keycard_auth/event_source var/mob/triggerer = null @@ -27,11 +27,11 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/keycard_auth, 26) /obj/machinery/keycard_auth/Initialize(mapload) . = ..() - ev = GLOB.keycard_events.addEvent("triggerEvent", CALLBACK(src, PROC_REF(triggerEvent))) + activated = GLOB.keycard_events.addEvent("triggerEvent", CALLBACK(src, PROC_REF(triggerEvent))) /obj/machinery/keycard_auth/Destroy() - GLOB.keycard_events.clearEvent("triggerEvent", ev) - QDEL_NULL(ev) + GLOB.keycard_events.clearEvent("triggerEvent", activated) + activated = null return ..() /obj/machinery/keycard_auth/ui_state(mob/user)