From ff1a3e9f0a437460d74e1f368db7961ca186ba8a Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Sat, 21 Oct 2017 19:55:50 -0400 Subject: [PATCH 1/2] Safeguards GetAllContents and makes it throw a warning --- code/__DEFINES/misc.dm | 4 +++- code/__HELPERS/unsorted.dm | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/code/__DEFINES/misc.dm b/code/__DEFINES/misc.dm index b83fc3dd39..66c12adc72 100644 --- a/code/__DEFINES/misc.dm +++ b/code/__DEFINES/misc.dm @@ -468,4 +468,6 @@ GLOBAL_LIST_INIT(ghost_others_options, list(GHOST_OTHERS_SIMPLE, GHOST_OTHERS_DE #define DUMMY_HUMAN_SLOT_MANIFEST "dummy_manifest_generation" #define PR_ANNOUNCEMENTS_PER_ROUND 5 //The number of unique PR announcements allowed per round - //This makes sure that a single person can only spam 3 reopens and 3 closes before being ignored \ No newline at end of file + //This makes sure that a single person can only spam 3 reopens and 3 closes before being ignored + +#define MAX_PROC_DEPTH 195 // 200 proc calls deep and shit breaks, this is a bit lower to give some safety room \ No newline at end of file diff --git a/code/__HELPERS/unsorted.dm b/code/__HELPERS/unsorted.dm index cae42d62e8..ff0693a839 100644 --- a/code/__HELPERS/unsorted.dm +++ b/code/__HELPERS/unsorted.dm @@ -503,12 +503,31 @@ Turf and target are separate in case you want to teleport some distance from a t var/y=arcsin(x/sqrt(1+x*x)) return y +<<<<<<< HEAD /atom/proc/GetAllContents(list/output=list()) . = output output += src for(var/i in 1 to contents.len) var/atom/thing = contents[i] thing.GetAllContents(output) +======= +/* +Recursively gets all contents of contents and returns them all in a list. + +recursive_depth is useful if you only want a turf and everything on it (recursive_depth=1) +Do not set recursive depth higher than MAX_PROC_DEPTH as byond breaks when that limit is reached. +*/ +/atom/proc/GetAllContents(list/output=list(), recursive_depth=MAX_PROC_DEPTH, _current_depth=0) + . = output + output += src + if(_current_depth == recursive_depth) + if(_current_depth == MAX_PROC_DEPTH) + WARNING("Get all contents reached the max recursive depth of [MAX_PROC_DEPTH]. More and we would break shit. Offending atom: [src]") + return + for(var/i in 1 to contents.len) + var/atom/thing = contents[i] + thing.GetAllContents(output, recursive_depth, ++_current_depth) +>>>>>>> 179cd9d... Merge pull request #31927 from ninjanomnom/recursive-depth //Step-towards method of determining whether one atom can see another. Similar to viewers() /proc/can_see(atom/source, atom/target, length=5) // I couldnt be arsed to do actual raycasting :I This is horribly inaccurate. From 7eb2af06c3253f356e4701b10bd08bb94aabf930 Mon Sep 17 00:00:00 2001 From: Poojawa Date: Sat, 21 Oct 2017 22:18:19 -0500 Subject: [PATCH 2/2] fixes compile --- code/__HELPERS/unsorted.dm | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/code/__HELPERS/unsorted.dm b/code/__HELPERS/unsorted.dm index ff0693a839..75e912dee7 100644 --- a/code/__HELPERS/unsorted.dm +++ b/code/__HELPERS/unsorted.dm @@ -503,14 +503,6 @@ Turf and target are separate in case you want to teleport some distance from a t var/y=arcsin(x/sqrt(1+x*x)) return y -<<<<<<< HEAD -/atom/proc/GetAllContents(list/output=list()) - . = output - output += src - for(var/i in 1 to contents.len) - var/atom/thing = contents[i] - thing.GetAllContents(output) -======= /* Recursively gets all contents of contents and returns them all in a list. @@ -519,15 +511,14 @@ Do not set recursive depth higher than MAX_PROC_DEPTH as byond breaks when that */ /atom/proc/GetAllContents(list/output=list(), recursive_depth=MAX_PROC_DEPTH, _current_depth=0) . = output - output += src + output += src if(_current_depth == recursive_depth) if(_current_depth == MAX_PROC_DEPTH) WARNING("Get all contents reached the max recursive depth of [MAX_PROC_DEPTH]. More and we would break shit. Offending atom: [src]") return - for(var/i in 1 to contents.len) - var/atom/thing = contents[i] - thing.GetAllContents(output, recursive_depth, ++_current_depth) ->>>>>>> 179cd9d... Merge pull request #31927 from ninjanomnom/recursive-depth + for(var/i in 1 to contents.len) + var/atom/thing = contents[i] + thing.GetAllContents(output, recursive_depth, ++_current_depth) //Step-towards method of determining whether one atom can see another. Similar to viewers() /proc/can_see(atom/source, atom/target, length=5) // I couldnt be arsed to do actual raycasting :I This is horribly inaccurate.