Skip to content

Commit

Permalink
Somewhat cursed lateload z-level minimap hard del fix (#14017)
Browse files Browse the repository at this point in the history
* dumb test fix

* Ivan's fixes as well

* wrong place for unregister

* wuh

* just in case

* this is dumb

* some more comment

* general cleanup
  • Loading branch information
Lumipharon authored Sep 25, 2023
1 parent e3c7e8b commit ca03545
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
24 changes: 17 additions & 7 deletions code/controllers/subsystem/minimaps.dm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ SUBSYSTEM_DEF(minimaps)
///assoc list of hash = image of images drawn by players
var/list/image/drawn_images = list()
///list of callbacks we need to invoke late because Initialize happens early, or a Z-level was loaded after init
var/list/datum/callback/earlyadds = list()
var/list/list/datum/callback/earlyadds = list()
///assoc list of minimap objects that are hashed so we have to update as few as possible
var/list/hashed_minimaps = list()

Expand Down Expand Up @@ -138,8 +138,8 @@ SUBSYSTEM_DEF(minimaps)
if(!earlyadds["[level]"])
return

for(var/i=1 to length(earlyadds["[level]"]))
earlyadds["[level]"][i].Invoke()
for(var/datum/callback/callback AS in earlyadds["[level]"])
callback.Invoke()
earlyadds["[level]"] = null //then clear them

/**
Expand Down Expand Up @@ -223,9 +223,8 @@ SUBSYSTEM_DEF(minimaps)
CRASH("Invalid marker added to subsystem")

if(!initialized || !(minimaps_by_z["[target.z]"])) //the minimap doesn't exist yet, z level was probably loaded after init
if(!(earlyadds["[target.z]"]))
earlyadds["[target.z]"] = list()
earlyadds["[target.z]"] += CALLBACK(src, PROC_REF(add_marker), target, hud_flags, blip)
LAZYADDASSOC(earlyadds, "[target.z]", CALLBACK(src, PROC_REF(add_marker), target, hud_flags, blip))
RegisterSignal(target, COMSIG_QDELETING, PROC_REF(remove_earlyadd), override = TRUE) //Override required for late z-level loading to prevent hard dels where an atom is initiated during z load, but is qdel'd before it finishes
return

var/turf/target_turf = get_turf(target)
Expand All @@ -244,7 +243,18 @@ SUBSYSTEM_DEF(minimaps)
RegisterSignal(target, COMSIG_MOVABLE_Z_CHANGED, PROC_REF(on_z_change))
blip.RegisterSignal(target, COMSIG_MOVABLE_MOVED, TYPE_PROC_REF(/image, minimap_on_move))
removal_cbs[target] = CALLBACK(src, PROC_REF(removeimage), blip, target, hud_flags)
RegisterSignal(target, COMSIG_QDELETING, PROC_REF(remove_marker))
RegisterSignal(target, COMSIG_QDELETING, PROC_REF(remove_marker), override = TRUE) //override for atoms that were on a late loaded z-level, overrides the remove_earlyadd above

///Removes the object from the earlyadds list, in case it was qdel'd before the z-level was fully loaded
/datum/controller/subsystem/minimaps/proc/remove_earlyadd(atom/source)
SIGNAL_HANDLER
remove_marker(source)
for(var/datum/callback/callback in earlyadds["[source.z]"])
if(callback.arguments[1] != source)
continue
earlyadds["[source.z]"] -= callback
UnregisterSignal(source, COMSIG_QDELETING)
return

/**
* removes an image from raw tracked lists, invoked by callback
Expand Down
3 changes: 2 additions & 1 deletion code/modules/vehicles/unmanned/unmanned_vehicle.dm
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@
SSminimaps.add_marker(src, MINIMAP_FLAG_MARINE, image('icons/UI_icons/map_blips.dmi', null, "uav"))

/obj/vehicle/unmanned/Destroy()
. = ..()
GLOB.unmanned_vehicles -= src
QDEL_NULL(flash)
QDEL_NULL(in_chamber)
return ..()

/obj/vehicle/unmanned/obj_destruction()
robogibs(src)
Expand Down

0 comments on commit ca03545

Please sign in to comment.