diff --git a/src/p_tick.c b/src/p_tick.c index 4ed8fd83a..ac6413d73 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -310,10 +310,18 @@ void P_RemoveThinker(thinker_t *thinker) mobj_t *P_SetTarget(mobj_t **mop, mobj_t *targ) { - if (*mop) // If there was a target already, decrease its refcount + if (*mop) // If there was a target already, decrease its refcount + { (*mop)->thinker.references--; -if ((*mop = targ) != NULL) // Set new target and if non-NULL, increase its counter + } + + if (targ != NULL) // Set new target and if non-NULL, increase its counter + { targ->thinker.references++; + } + + *mop = targ; + return targ; }