From fb51f60e20746efa6aa24f90ac75c7a5eda1e13e Mon Sep 17 00:00:00 2001 From: Ashnal Date: Tue, 14 Jul 2020 00:21:46 -0400 Subject: [PATCH] Add clean up to K_PuntMine This cleans up hnext when a mine shield is P_RemoveMobj'ed while being punted Otherwise, hnext could point to a removed mobj and cause undefined behavior This also fixes the bug where if you have multiple mines in your slot, drag one and have it punted, all your unused mines would disappear. This should/may fix the crashes/desyncs I've observed in gameplay when a held mine is punted. --- src/k_kart.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/k_kart.c b/src/k_kart.c index cc5504bb4..c1a0bef19 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -3312,7 +3312,8 @@ void K_PuntMine(mobj_t *thismine, mobj_t *punter) if (!thismine || P_MobjWasRemoved(thismine)) return; - if (thismine->type == MT_SSMINE_SHIELD) // Create a new mine + //This guarantees you hit a mine being dragged + if (thismine->type == MT_SSMINE_SHIELD) // Create a new mine, and clean up the old one { mine = P_SpawnMobj(thismine->x, thismine->y, thismine->z, MT_SSMINE); P_SetTarget(&mine->target, thismine->target); @@ -3320,7 +3321,19 @@ void K_PuntMine(mobj_t *thismine, mobj_t *punter) mine->flags2 = thismine->flags2; mine->floorz = thismine->floorz; mine->ceilingz = thismine->ceilingz; + + //Since we aren't using P_KillMobj, we need to clean up the hnext reference + { + P_SetTarget(&thismine->target->hnext, NULL); //target is the player who owns the mine + thismine->target->player->kartstuff[k_bananadrag] = 0; + thismine->target->player->kartstuff[k_itemheld] = 0; + + if (--thismine->target->player->kartstuff[k_itemamount] <= 0) + thismine->target->player->kartstuff[k_itemtype] = KITEM_NONE; + } + P_RemoveMobj(thismine); + } else mine = thismine;