From 4f3029fcb2ce43f9b76225d96551a61358c7e17e Mon Sep 17 00:00:00 2001 From: Leshana Date: Tue, 11 Apr 2017 19:16:35 -0400 Subject: [PATCH] Fix null pointer runtime in scheduled task controller. * If the "scheduler" controller is restarted by the process scheduler for any reason, it will start throwing runtimes every status panel update because the new replacement instance doesn't initialize its list of schedule tasks. * Fix that by copying over the unfinished list from the old instance, but doing some safety checks to make sure it doesn't copy over bad stuff. --- code/controllers/Processes/scheduler.dm | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/code/controllers/Processes/scheduler.dm b/code/controllers/Processes/scheduler.dm index fdbe55faed..276249bd55 100644 --- a/code/controllers/Processes/scheduler.dm +++ b/code/controllers/Processes/scheduler.dm @@ -25,6 +25,21 @@ catchException(e, last_object) SCHECK +// We've been restarted, probably due to having a massive list of tasks. +// Lets copy over the task list as safely as we can and try to chug thru it... +// Note: We won't be informed about tasks being destroyed, but this is the best we can do. +/datum/controller/process/scheduler/copyStateFrom(var/datum/controller/process/scheduler/target) + scheduled_tasks = list() + for(var/st in target.scheduled_tasks) + if(!deleted(st) && istype(st, /datum/scheduled_task)) + schedule(st) + scheduler = src + +// We are being killed. Least we can do is deregister all those events we registered +/datum/controller/process/scheduler/onKill() + for(var/st in scheduled_tasks) + destroyed_event.unregister(st, src) + /datum/controller/process/scheduler/statProcess() ..() stat(null, "[scheduled_tasks.len] task\s") @@ -130,4 +145,4 @@ /proc/repeat_scheduled_task(var/trigger_delay, var/datum/scheduled_task/st) st.trigger_time = world.time + trigger_delay - scheduler.schedule(st) \ No newline at end of file + scheduler.schedule(st)