From 8b509623c0e28fb77f0366571a6f8fec5e072be0 Mon Sep 17 00:00:00 2001 From: Kashargul <144968721+Kashargul@users.noreply.github.com> Date: Thu, 31 Oct 2024 10:54:02 +0100 Subject: [PATCH] fixes some MC crashes with turf examine (#16540) * fixes some MC crashes with turf examine * properly handle turf deletion or same turf examines * recodes turf examine to move it to client * . * use function * update signals on mind transfer * ok this would require a lot more component handling --- code/controllers/subsystems/statpanel.dm | 56 ++++++++++++------------ code/datums/mind.dm | 1 + code/modules/mob/mob_defines.dm | 1 - 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/code/controllers/subsystems/statpanel.dm b/code/controllers/subsystems/statpanel.dm index 870d32b1ec3..f0cd7555f66 100644 --- a/code/controllers/subsystems/statpanel.dm +++ b/code/controllers/subsystems/statpanel.dm @@ -203,12 +203,12 @@ SUBSYSTEM_DEF(statpanels) return var/list/overrides = list() for(var/image/target_image as anything in target.images) - if(!target_image.loc || target_image.loc.loc != target_mob.listed_turf || !target_image.override) + if(!target_image.loc || target_image.loc.loc != target.tracked_turf || !target_image.override) continue overrides += target_image.loc - var/list/atoms_to_display = list(target_mob.listed_turf) - for(var/atom/movable/turf_content as anything in target_mob.listed_turf) + var/list/atoms_to_display = list(target.tracked_turf) + for(var/atom/movable/turf_content as anything in target.tracked_turf) if(turf_content.mouse_opacity == MOUSE_OPACITY_TRANSPARENT) continue if(turf_content.invisibility > target_mob.see_invisible) @@ -319,12 +319,11 @@ SUBSYSTEM_DEF(statpanels) // Handle turfs - if(target_mob?.listed_turf) - if(!target_mob.TurfAdjacent(target_mob.listed_turf)) - target.stat_panel.send_message("removed_listedturf") - target_mob.listed_turf = null + if(target.tracked_turf) + if(!target_mob.TurfAdjacent(target.tracked_turf)) + target_mob.set_listed_turf(null) - else if(target.stat_tab == target_mob?.listed_turf.name || !(target_mob?.listed_turf.name in target.panel_tabs)) + else if(target.stat_tab == target.tracked_turf.name || !(target.tracked_turf.name in target.panel_tabs)) set_turf_examine_tab(target, target_mob) return TRUE @@ -351,6 +350,8 @@ SUBSYSTEM_DEF(statpanels) /// Stat panel window declaration /client/var/datum/tgui_window/stat_panel +/// Turf examine turf +/client/var/turf/tracked_turf /// Datum that holds and tracks info about a client's object window /// Really only exists because I want to be able to do logic with signals @@ -365,8 +366,6 @@ SUBSYSTEM_DEF(statpanels) var/list/atoms_to_imagify = list() /// Our owner client var/client/parent - /// Are we currently tracking a turf? - var/actively_tracking = FALSE ///For reusing this logic for examines var/atom/examine_target var/flags = 0 @@ -418,28 +417,31 @@ SUBSYSTEM_DEF(statpanels) if(!length(to_make)) return PROCESS_KILL -/datum/object_window_info/proc/start_turf_tracking() - if(actively_tracking) +/datum/object_window_info/proc/start_turf_tracking(turf/new_turf) + if(parent.tracked_turf) stop_turf_tracking() var/static/list/connections = list( COMSIG_MOVABLE_MOVED = PROC_REF(on_mob_move), COMSIG_MOB_LOGOUT = PROC_REF(on_mob_logout), ) AddComponent(/datum/component/connect_mob_behalf, parent, connections) - RegisterSignal(parent.mob.listed_turf, COMSIG_ATOM_ENTERED, PROC_REF(turflist_changed)) - RegisterSignal(parent.mob.listed_turf, COMSIG_ATOM_EXITED, PROC_REF(turflist_changed)) - actively_tracking = TRUE + RegisterSignal(parent.tracked_turf, COMSIG_ATOM_ENTERED, PROC_REF(turflist_changed)) + RegisterSignal(parent.tracked_turf, COMSIG_ATOM_EXITED, PROC_REF(turflist_changed)) + parent.stat_panel.send_message("create_listedturf", new_turf) + parent.tracked_turf = new_turf /datum/object_window_info/proc/stop_turf_tracking() - qdel(GetComponent(/datum/component/connect_mob_behalf)) - UnregisterSignal(parent.mob.listed_turf, COMSIG_ATOM_ENTERED) - UnregisterSignal(parent.mob.listed_turf, COMSIG_ATOM_EXITED) - actively_tracking = FALSE + if(GetComponent(/datum/component/connect_mob_behalf)) + qdel(GetComponent(/datum/component/connect_mob_behalf)) + if(parent.tracked_turf) + UnregisterSignal(parent.tracked_turf, COMSIG_ATOM_ENTERED) + UnregisterSignal(parent.tracked_turf, COMSIG_ATOM_EXITED) + parent.stat_panel.send_message("remove_listedturf") + parent.tracked_turf = null /datum/object_window_info/proc/on_mob_move(mob/source) SIGNAL_HANDLER - var/turf/listed = source.listed_turf - if(!listed || !source.TurfAdjacent(listed)) + if(!parent.tracked_turf || !source.TurfAdjacent(parent.tracked_turf)) source.set_listed_turf(null) /datum/object_window_info/proc/on_mob_logout(mob/source) @@ -466,16 +468,12 @@ SUBSYSTEM_DEF(statpanels) /mob/proc/set_listed_turf(turf/new_turf) if(!client) - listed_turf = new_turf return if(!client.obj_window) client.obj_window = new(client) + if(client.tracked_turf == new_turf) + return if(!new_turf) client.obj_window.stop_turf_tracking() //Needs to go before listed_turf is set to null so signals can be removed - listed_turf = new_turf - - if(listed_turf) - client.stat_panel.send_message("create_listedturf", listed_turf.name) - client.obj_window.start_turf_tracking() - else - client.stat_panel.send_message("remove_listedturf") + return + client.obj_window.start_turf_tracking(new_turf) diff --git a/code/datums/mind.dm b/code/datums/mind.dm index 43f41708764..17b39256456 100644 --- a/code/datums/mind.dm +++ b/code/datums/mind.dm @@ -105,6 +105,7 @@ if(new_character.client) new_character.client.init_verbs() // re-initialize character specific verbs + new_character.set_listed_turf(null) /datum/mind/proc/store_memory(new_text) memory += "[new_text]
" diff --git a/code/modules/mob/mob_defines.dm b/code/modules/mob/mob_defines.dm index d8db6a7394b..26118480b04 100644 --- a/code/modules/mob/mob_defines.dm +++ b/code/modules/mob/mob_defines.dm @@ -208,7 +208,6 @@ //so don't treat them as being SSD even though their client var is null. var/mob/teleop = null - var/turf/listed_turf = null //the current turf being examined in the stat panel var/list/shouldnt_see = list(/mob/observer/eye) //list of objects that this mob shouldn't see in the stat panel. this silliness is needed because of AI alt+click and cult blood runes var/list/active_genes=list()