Skip to content

Commit

Permalink
[MIRROR] Fix bad reference management in object overlay circuit (#1856)
Browse files Browse the repository at this point in the history
* Fix bad reference management in object overlay circuit  (#81338)

---------

Co-authored-by: NovaBot <[email protected]>
Co-authored-by: MrMelbert <[email protected]>
  • Loading branch information
3 people authored Feb 8, 2024
1 parent 1cfdfcd commit 2707a7f
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions code/modules/wiremod/components/bci/hud/object_overlay.dm
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@
var/datum/port/input/signal_on
var/datum/port/input/signal_off

/// Reference to the BCI we're implanted inside
var/obj/item/organ/internal/cyberimp/bci/bci

/// Assoc list of REF to the target atom to the overlay alt appearance it is using
var/list/active_overlays = list()

var/list/options_map

/obj/item/circuit_component/object_overlay/populate_ports()
Expand All @@ -42,8 +46,7 @@
image_rotation = add_input_port("Overlay Rotation", PORT_TYPE_NUMBER)

/obj/item/circuit_component/object_overlay/Destroy()
for(var/active_overlay in active_overlays)
QDEL_NULL(active_overlay)
QDEL_LIST_ASSOC_VAL(active_overlays)
return ..()

/obj/item/circuit_component/object_overlay/populate_options()
Expand Down Expand Up @@ -78,26 +81,24 @@
var/mob/living/owner = bci.owner
var/atom/target_atom = target.value

if(!owner || !istype(owner) || !owner.client || !target_atom)
if(!istype(owner) || !owner.client || isnull(target_atom))
return

if(COMPONENT_TRIGGERED_BY(signal_on, port))
show_to_owner(target_atom, owner)

if(COMPONENT_TRIGGERED_BY(signal_off, port) && (target_atom in active_overlays))
var/datum/weakref/overlay_ref = active_overlays[target_atom]
var/datum/atom_hud/overlay = overlay_ref?.resolve()
QDEL_NULL(overlay)
active_overlays.Remove(target_atom)
var/datum/atom_hud/existing_overlay = active_overlays[REF(target_atom)]
if(COMPONENT_TRIGGERED_BY(signal_off, port) && !isnull(existing_overlay))
qdel(existing_overlay)
active_overlays -= REF(target_atom)

/obj/item/circuit_component/object_overlay/proc/show_to_owner(atom/target_atom, mob/living/owner)
if(LAZYLEN(active_overlays) >= OBJECT_OVERLAY_LIMIT)
if(length(active_overlays) >= OBJECT_OVERLAY_LIMIT)
return

if(active_overlays[target_atom])
var/datum/weakref/overlay_ref = active_overlays[target_atom]
var/datum/atom_hud/overlay = overlay_ref?.resolve()
QDEL_NULL(overlay)
var/datum/atom_hud/existing_overlay = active_overlays[REF(target_atom)]
if(!isnull(existing_overlay))
qdel(existing_overlay)

var/image/cool_overlay = image(icon = 'icons/hud/screen_bci.dmi', loc = target_atom, icon_state = options_map[object_overlay_options.value], layer = RIPPLE_LAYER)
SET_PLANE_EXPLICIT(cool_overlay, ABOVE_LIGHTING_PLANE, target_atom)
Expand All @@ -121,15 +122,11 @@
)
alt_appearance.show_to(owner)

active_overlays[target_atom] = WEAKREF(alt_appearance)
active_overlays[REF(target_atom)] = alt_appearance

/obj/item/circuit_component/object_overlay/proc/on_organ_removed(datum/source, mob/living/carbon/owner)
SIGNAL_HANDLER

for(var/atom/target_atom in active_overlays)
var/datum/weakref/overlay_ref = active_overlays[target_atom]
var/datum/atom_hud/overlay = overlay_ref?.resolve()
QDEL_NULL(overlay)
active_overlays.Remove(target_atom)
QDEL_LIST_ASSOC_VAL(active_overlays)

#undef OBJECT_OVERLAY_LIMIT

0 comments on commit 2707a7f

Please sign in to comment.