From 8b049ff877619a34bf2e2e4ed60f012ed0bd5bb4 Mon Sep 17 00:00:00 2001 From: moxian Date: Wed, 22 Jun 2022 07:18:35 +0000 Subject: [PATCH] Fix stack overflow in mutual grabs (#18032) If you grab someone who grabs you, and either of you try to move you'd get stack overflow. No more. --- code/modules/mob/living/living.dm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/code/modules/mob/living/living.dm b/code/modules/mob/living/living.dm index 0ec0a969ef1..e823161f01c 100644 --- a/code/modules/mob/living/living.dm +++ b/code/modules/mob/living/living.dm @@ -572,11 +572,19 @@ /mob/living/proc/pull_grabbed(turf/old_turf, direct, movetime) if(!Adjacent(old_turf)) return + // We might not actually be grab pulled, but we are pretending that we are, so as to + // hackily work around issues arising from mutual grabs. + var/old_being_pulled = currently_grab_pulled + currently_grab_pulled = TRUE // yes, this is four distinct `for` loops. No, they can't be merged. var/list/grabbing = list() for(var/mob/M in ret_grab()) - if(src != M) - grabbing |= M + if(src == M) + continue + if(M.currently_grab_pulled) + // Being already pulled by something else up the call stack. + continue + grabbing |= M for(var/mob/M in grabbing) M.currently_grab_pulled = TRUE M.animate_movement = SYNC_STEPS @@ -613,6 +621,8 @@ for(var/obj/item/grab/G in grabbed_by) G.adjust_position() + currently_grab_pulled = old_being_pulled + /mob/living/proc/makeTrail(turf/T) if(!has_gravity(src))