From 629f433cccd048136870ae0cc48f17674013e281 Mon Sep 17 00:00:00 2001 From: SteelSlayer Date: Sun, 6 Sep 2020 10:08:40 -0500 Subject: [PATCH 1/4] SScleanup --- code/__DEFINES/subsystems.dm | 4 +-- code/controllers/subsystem/cleanup.dm | 40 +++++++++++++++++++++++++++ paradise.dme | 1 + 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 code/controllers/subsystem/cleanup.dm diff --git a/code/__DEFINES/subsystems.dm b/code/__DEFINES/subsystems.dm index 153eca7f373..392f6e2e4dd 100644 --- a/code/__DEFINES/subsystems.dm +++ b/code/__DEFINES/subsystems.dm @@ -48,7 +48,7 @@ #define INIT_ORDER_GARBAGE 19 #define INIT_ORDER_DBCORE 18 #define INIT_ORDER_BLACKBOX 17 -#define INIT_ORDER_SERVER_MAINT 16 +#define INIT_ORDER_CLEANUP 16 #define INIT_ORDER_INPUT 15 #define INIT_ORDER_RESEARCH 14 #define INIT_ORDER_EVENTS 13 @@ -89,7 +89,7 @@ #define FIRE_PRIORITY_NANOMOB 10 #define FIRE_PRIORITY_NIGHTSHIFT 10 #define FIRE_PRIORITY_IDLE_NPC 10 -#define FIRE_PRIORITY_SERVER_MAINT 10 +#define FIRE_PRIORITY_CLEANUP 10 #define FIRE_PRIORITY_TICKETS 10 #define FIRE_PRIORITY_RESEARCH 10 #define FIRE_PRIORITY_GARBAGE 15 diff --git a/code/controllers/subsystem/cleanup.dm b/code/controllers/subsystem/cleanup.dm new file mode 100644 index 00000000000..51ae9c02ef8 --- /dev/null +++ b/code/controllers/subsystem/cleanup.dm @@ -0,0 +1,40 @@ +/** + * # Cleanup Subsystem + * + * For now, all it does is periodically clean the supplied global lists of any null values they may contain. + * + * Why is this important? + * + * Sometimes, these lists can gain nulls due to errors. + * For example, when a dead player trasitions from the `dead_mob_list` to the `alive_mob_list`, a null value may get stuck in the dead mob list. + * This can cause issues when other code tries to do things with the values in the list, but are instead met with null values. + * These problems are incredibly hard to track down and fix, so this subsystem is a solution to that. + */ +SUBSYSTEM_DEF(cleanup) + name = "Null cleanup" + wait = 30 SECONDS + flags = SS_POST_FIRE_TIMING + priority = FIRE_PRIORITY_CLEANUP + init_order = INIT_ORDER_CLEANUP + runlevels = RUNLEVEL_LOBBY | RUNLEVELS_DEFAULT + offline_implications = "Certain global lists will no longer be cleared of nulls, which may result in runtimes. No immediate action is needed." + /// A list of global lists we want the subsystem to clean. + var/list/lists_to_clean + +/datum/controller/subsystem/cleanup/Initialize(start_timeofday) + . = ..() + // If you want this subsystem to clean out nulls from a specific list, add it here. + lists_to_clean = list( + GLOB.clients, + GLOB.player_list, + GLOB.mob_list, + GLOB.alive_mob_list, + GLOB.dead_mob_list, + GLOB.human_list, + GLOB.carbon_list + ) + +/datum/controller/subsystem/cleanup/fire(resumed) + for(var/L in lists_to_clean) + var/list/_list = L + listclearnulls(_list) diff --git a/paradise.dme b/paradise.dme index 5e88b673231..1577b6b1144 100644 --- a/paradise.dme +++ b/paradise.dme @@ -216,6 +216,7 @@ #include "code\controllers\subsystem\atoms.dm" #include "code\controllers\subsystem\changelog.dm" #include "code\controllers\subsystem\chat.dm" +#include "code\controllers\subsystem\cleanup.dm" #include "code\controllers\subsystem\events.dm" #include "code\controllers\subsystem\fires.dm" #include "code\controllers\subsystem\garbage.dm" From eebc369704e579a1fb9d5edea355733003a097f9 Mon Sep 17 00:00:00 2001 From: SteelSlayer Date: Thu, 10 Sep 2020 12:57:06 -0500 Subject: [PATCH 2/4] adds runtime logging when a null is found --- code/controllers/subsystem/cleanup.dm | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/code/controllers/subsystem/cleanup.dm b/code/controllers/subsystem/cleanup.dm index 51ae9c02ef8..e572a0960ac 100644 --- a/code/controllers/subsystem/cleanup.dm +++ b/code/controllers/subsystem/cleanup.dm @@ -25,16 +25,20 @@ SUBSYSTEM_DEF(cleanup) . = ..() // If you want this subsystem to clean out nulls from a specific list, add it here. lists_to_clean = list( - GLOB.clients, - GLOB.player_list, - GLOB.mob_list, - GLOB.alive_mob_list, - GLOB.dead_mob_list, - GLOB.human_list, - GLOB.carbon_list + GLOB.clients = "clients", + GLOB.player_list = "player_list", + GLOB.mob_list = "mob_list", + GLOB.alive_mob_list = "alive_mob_list", + GLOB.dead_mob_list = "dead_mob_list", + GLOB.human_list = "human_list", + GLOB.carbon_list = "carbon_list" ) /datum/controller/subsystem/cleanup/fire(resumed) for(var/L in lists_to_clean) var/list/_list = L + var/prev_length = length(_list) listclearnulls(_list) + + if(length(_list) < prev_length) + log_runtime_txt("Found a null value in GLOB.[lists_to_clean[_list]]!") From 7f4f4c732808bca53ecfef666c179ec7feb14c51 Mon Sep 17 00:00:00 2001 From: SteelSlayer Date: Sat, 12 Sep 2020 17:46:57 -0500 Subject: [PATCH 3/4] Update cleanup.dm --- code/controllers/subsystem/cleanup.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/controllers/subsystem/cleanup.dm b/code/controllers/subsystem/cleanup.dm index e572a0960ac..7f5f32734a6 100644 --- a/code/controllers/subsystem/cleanup.dm +++ b/code/controllers/subsystem/cleanup.dm @@ -22,7 +22,6 @@ SUBSYSTEM_DEF(cleanup) var/list/lists_to_clean /datum/controller/subsystem/cleanup/Initialize(start_timeofday) - . = ..() // If you want this subsystem to clean out nulls from a specific list, add it here. lists_to_clean = list( GLOB.clients = "clients", @@ -33,6 +32,7 @@ SUBSYSTEM_DEF(cleanup) GLOB.human_list = "human_list", GLOB.carbon_list = "carbon_list" ) + return ..() /datum/controller/subsystem/cleanup/fire(resumed) for(var/L in lists_to_clean) From 5730e32fbf9062fe3a01cf19ebc355c88dcd4f00 Mon Sep 17 00:00:00 2001 From: SteelSlayer Date: Sat, 12 Sep 2020 18:41:22 -0500 Subject: [PATCH 4/4] stack_trace --- code/controllers/subsystem/cleanup.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/controllers/subsystem/cleanup.dm b/code/controllers/subsystem/cleanup.dm index 7f5f32734a6..f5962c45547 100644 --- a/code/controllers/subsystem/cleanup.dm +++ b/code/controllers/subsystem/cleanup.dm @@ -41,4 +41,4 @@ SUBSYSTEM_DEF(cleanup) listclearnulls(_list) if(length(_list) < prev_length) - log_runtime_txt("Found a null value in GLOB.[lists_to_clean[_list]]!") + stack_trace("Found a null value in GLOB.[lists_to_clean[_list]]!")