From 17aaf178d587970a3a845aa6c2f3807077996a77 Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 20 Mar 2023 19:37:36 -0700 Subject: [PATCH] PARANOIA: fix faulty references warning - Print mobj address and mobj type in addition to reference count - Print negative reference counts correctly - Don't print warning twice for the same mobj (don't spam the console) --- src/d_think.h | 1 + src/p_tick.c | 42 +++++++++++++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/d_think.h b/src/d_think.h index 186e151a0..d833f4ca0 100644 --- a/src/d_think.h +++ b/src/d_think.h @@ -58,6 +58,7 @@ struct thinker_t #ifdef PARANOIA INT32 debug_mobjtype; + tic_t debug_time; #endif }; diff --git a/src/p_tick.c b/src/p_tick.c index 27b52c2b7..acd7d2f95 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -296,20 +296,34 @@ static thinker_t *currentthinker; void P_RemoveThinkerDelayed(thinker_t *thinker) { thinker_t *next; -#ifdef PARANOIA -#define BEENAROUNDBIT (0x40000000) // has to be sufficiently high that it's unlikely to happen in regular gameplay. If you change this, pay attention to the bit pattern of INT32_MIN. - if (thinker->references & ~BEENAROUNDBIT) + + if (thinker->references != 0) { - if (thinker->references & BEENAROUNDBIT) // Usually gets cleared up in one frame; what's going on here, then? - CONS_Printf("Number of potentially faulty references: %d\n", (thinker->references & ~BEENAROUNDBIT)); - thinker->references |= BEENAROUNDBIT; +#ifdef PARANOIA + if (thinker->debug_time > leveltime) + { + thinker->debug_time = leveltime + 2; // do not print errors again + } + // Removed mobjs can be the target of another mobj. In + // that case, the other mobj will manage its reference + // to the removed mobj in P_MobjThinker. However, if + // the removed mobj is removed after the other object + // thinks, the reference management is delayed by one + // tic. + else if (thinker->debug_time < leveltime) + { + CONS_Printf( + "PARANOIA/P_RemoveThinkerDelayed: %p %s references=%d\n", + (void*)thinker, + MobjTypeName((mobj_t*)thinker), + thinker->references + ); + + thinker->debug_time = leveltime + 2; // do not print this error again + } +#endif return; } -#undef BEENAROUNDBIT -#else - if (thinker->references) - return; -#endif /* Remove from main thinker list */ next = thinker->next; @@ -376,12 +390,18 @@ mobj_t *P_SetTarget2(mobj_t **mop, mobj_t *targ source_line ); } + + (*mop)->thinker.debug_time = leveltime; #endif } if (targ != NULL) // Set new target and if non-NULL, increase its counter { targ->thinker.references++; + +#ifdef PARANOIA + targ->thinker.debug_time = leveltime; +#endif } *mop = targ;