From 3b1937684814df3e09280e9f7c1f5839d1595686 Mon Sep 17 00:00:00 2001 From: "James R." Date: Sun, 17 Sep 2023 19:12:12 -0700 Subject: [PATCH] append_hyudoro, pop_hyudoro: fix linked list handling - Use P_SetTarget to handle reference counting properly - Properly unlink from the start of the list --- src/objects/hyudoro.c | 50 +++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/src/objects/hyudoro.c b/src/objects/hyudoro.c index 32c190c92..c799c4ab4 100644 --- a/src/objects/hyudoro.c +++ b/src/objects/hyudoro.c @@ -91,7 +91,8 @@ get_look_angle (mobj_t *thing) static boolean is_hyudoro (mobj_t *thing) { - return thing && thing->type == MT_HYUDORO; + return !P_MobjWasRemoved(thing) && + thing->type == MT_HYUDORO; } static mobj_t * @@ -346,7 +347,7 @@ append_hyudoro } hyudoro_stackpos(hyu) = lastpos + 1; - *head = hyu; + P_SetTarget(head, hyu); } static void @@ -354,26 +355,37 @@ pop_hyudoro (mobj_t **head) { mobj_t *hyu = *head; - INT32 lastpos; - INT32 thispos; - - if (is_hyudoro(hyu)) + if (!is_hyudoro(hyu)) { - lastpos = hyudoro_stackpos(hyu); - hyu = hyudoro_next(hyu); - - while (is_hyudoro(hyu)) - { - thispos = hyudoro_stackpos(hyu); - - hyudoro_stackpos(hyu) = lastpos; - lastpos = thispos; - - hyu = hyudoro_next(hyu); - } + return; } - *head = hyu; + INT32 lastpos = hyudoro_stackpos(hyu); + + { + mobj_t *next = hyudoro_next(hyu); + + P_SetTarget(head, next); + P_SetTarget(&hyudoro_next(hyu), NULL); + + hyu = next; + } + + if (!is_hyudoro(hyu)) + { + return; + } + + do + { + INT32 thispos = hyudoro_stackpos(hyu); + + hyudoro_stackpos(hyu) = lastpos; + lastpos = thispos; + + hyu = hyudoro_next(hyu); + } + while (is_hyudoro(hyu)); } static void hyudoro_set_held_item_from_player