Alug committed 2025-04-23 16:02:41 +02:00
1 parent cd7177682a
commit 55704f2ba2
5 files changed
+139 -15

No files matched your search

+6
View File
@@ -17,6 +17,8 @@
#ifndef __D_THINK__
#define __D_THINK__
#include "doomdef.h"
#ifdef __GNUG__
#pragma interface
#endif
@@ -50,6 +52,10 @@ typedef struct thinker_s
// this one using pointers. Used for garbage collection.
INT32 references;
boolean cachable;
#ifdef PARANOIA
INT32 debug_mobjtype;
tic_t debug_time;
#endif
} thinker_t;
#endif
+8
View File
@@ -10132,6 +10132,10 @@ void P_RemoveMobj(mobj_t *mobj)
{ // Add thinker just to delay removing it until refrences are gone.
mobj->flags &= ~MF_NOTHINK;
P_AddThinker((thinker_t *)mobj);
#ifdef PARANOIA
// Saved to avoid being scrambled like below...
mobj->thinker.debug_mobjtype = mobj->type;
#endif
#ifdef SCRAMBLE_REMOVED
// Invalidate mobj_t data to cause crashes if accessed!
memset((UINT8 *)mobj + sizeof(thinker_t), 0xff, sizeof(mobj_t) - sizeof(thinker_t));
@@ -10141,6 +10145,10 @@ void P_RemoveMobj(mobj_t *mobj)
}
else
{
#ifdef PARANOIA
// Saved to avoid being scrambled like below...
mobj->thinker.debug_mobjtype = mobj->type;
#endif
#ifdef SCRAMBLE_REMOVED
// Invalidate mobj_t data to cause crashes if accessed!
memset((UINT8 *)mobj + sizeof(thinker_t), 0xff, sizeof(mobj_t) - sizeof(thinker_t));
+3
View File
@@ -156,6 +156,9 @@ FUNCINLINE static ATTRINLINE void PolyObj_AddThinker(thinker_t *th)
th->references = 0;
th->cachable = false; // not initialising this made the mobjcache die thx!
#ifdef PARANOIA
th->debug_mobjtype = MT_NULL;
#endif
}
static void FreeSideLists(void)
+109 -14
View File
@@ -11,6 +11,10 @@
/// \file p_tick.c
/// \brief Archiving: SaveGame I/O, Thinker, Ticker
#ifdef PARANOIA
#include "dehacked.h" // MOBJTYPE_LIST
#endif
#include "doomstat.h"
#include "g_game.h"
#include "g_input.h"
@@ -204,6 +208,9 @@ void P_AddThinker(thinker_t *thinker)
thinker->references = 0; // killough 11/98: init reference counter to 0
thinker->cachable = (thinker->function.acp1 == (actionf_p1)P_MobjThinker);
#ifdef PARANOIA
thinker->debug_mobjtype = MT_NULL;
#endif
}
//
@@ -220,8 +227,48 @@ void P_AddPrecipThinker(thinker_t *thinker)
thinker->references = 0; // killough 11/98: init reference counter to 0
thinker->cachable = false;
#ifdef PARANOIA
thinker->debug_mobjtype = MT_NULL;
#endif
}
#ifdef PARANOIA
static const char *MobjTypeName(const mobj_t *mobj)
{
actionf_p1 p1 = mobj->thinker.function.acp1;
if (p1 == (actionf_p1)P_MobjThinker)
{
return MOBJTYPE_LIST[mobj->type];
}
else if (p1 == (actionf_p1)P_RemoveThinkerDelayed)
{
if (mobj->thinker.debug_mobjtype != MT_NULL)
{
return MOBJTYPE_LIST[mobj->thinker.debug_mobjtype];
}
}
return "<Not a mobj>";
}
static const char *MobjThinkerName(const mobj_t *mobj)
{
actionf_p1 p1 = mobj->thinker.function.acp1;
if (p1 == (actionf_p1)P_MobjThinker)
{
return "P_MobjThinker";
}
else if (p1 == (actionf_p1)P_RemoveThinkerDelayed)
{
return "P_RemoveThinkerDelayed";
}
return "<Unknown Thinker>";
}
#endif
//
// killough 11/98:
//
@@ -242,20 +289,35 @@ static thinker_t *currentthinker;
//
void P_RemoveThinkerDelayed(thinker_t *thinker)
{
#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
// 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 (or two?)
const UINT8 delay = 2;
if (thinker->debug_time > leveltime)
{
thinker->debug_time = leveltime + delay + 1; // do not print errors again
}
else if ((thinker->debug_time + delay) <= leveltime)
{
CONS_Printf(
"PARANOIA/P_RemoveThinkerDelayed: %p %s references=%d\n",
(void*)thinker,
MobjTypeName((mobj_t*)thinker),
thinker->references
);
thinker->debug_time = leveltime + delay + 1; // do not print this error again
}
#endif
return;
}
#undef BEENAROUNDBIT
#else
if (thinker->references != 0)
return;
#endif
/* Remove from main thinker list */
thinker_t *next = thinker->next;
@@ -333,12 +395,45 @@ void P_RemoveThinker(thinker_t *thinker)
* references, and delay removal until the count is 0.
*/
mobj_t *P_SetTarget(mobj_t **mop, mobj_t *targ)
mobj_t *P_SetTarget2(mobj_t **mop, mobj_t *targ
#ifdef PARANOIA
, const char *source_file, int source_line
#endif
)
{
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
#ifdef PARANOIA
if ((*mop)->thinker.references < 0)
{
CONS_Printf(
"PARANOIA/P_SetTarget: %p %s %s references=%d, references go negative! (%s:%d)\n",
(void*)*mop,
MobjTypeName(*mop),
MobjThinkerName(*mop),
(*mop)->thinker.references,
source_file,
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;
return targ;
}
+13 -1
View File
@@ -14,6 +14,8 @@
#ifndef __P_TICK__
#define __P_TICK__
#include "doomdef.h"
#ifdef __GNUG__
#pragma interface
#endif
@@ -29,6 +31,16 @@ void P_Ticker(boolean run);
void P_PreTicker(INT32 frames);
void P_DoTeamscrambling(void);
void P_RemoveThinkerDelayed(thinker_t *thinker);
mobj_t *P_SetTarget(mobj_t **mo, mobj_t *target); // killough 11/98
mobj_t *P_SetTarget2(mobj_t **mo, mobj_t *target
#ifdef PARANOIA
, const char *source_file, int source_line
#endif
);
#ifdef PARANOIA
#define P_SetTarget(...) P_SetTarget2(__VA_ARGS__, __FILE__, __LINE__)
#else
#define P_SetTarget P_SetTarget2
#endif
#endif