thinker_era

A first pass in attempts to fix crashes when ACS causes map changes.
Frustratingly still got a crash, but I think this is definitely the right foundation to work with.
This commit is contained in:
toaster 2023-11-04 17:11:59 +00:00
parent 6e6c0cd71f
commit dce2c73df1
5 changed files with 31 additions and 4 deletions

View file

@ -350,10 +350,13 @@ ACSVM::Word Environment::callSpecImpl
activator_t *activator = static_cast<activator_t *>(Z_Calloc(sizeof(activator_t), PU_LEVEL, nullptr));
auto __ = srb2::finally(
[activator]()
[info, activator]()
{
P_SetTarget(&activator->mo, NULL);
Z_Free(activator);
if (info->thread_era == thinker_era)
{
P_SetTarget(&activator->mo, NULL);
Z_Free(activator);
}
}
);

View file

@ -59,6 +59,7 @@ enum acs_tagType_e
class ThreadInfo : public ACSVM::ThreadInfo
{
public:
UINT32 thread_era; // If equal to thinker_era, mobj pointers are safe.
mobj_t *mo; // Object that activated this thread.
line_t *line; // Linedef that activated this thread.
UINT8 side; // Front / back side of said linedef.
@ -67,6 +68,7 @@ public:
bool fromLineSpecial; // Called from P_ProcessLineSpecial.
ThreadInfo() :
thread_era { thinker_era },
mo{ nullptr },
line{ nullptr },
side{ 0 },
@ -77,6 +79,7 @@ public:
}
ThreadInfo(const ThreadInfo &info) :
thread_era { thinker_era },
mo{ nullptr },
line{ info.line },
side{ info.side },
@ -88,6 +91,7 @@ public:
}
ThreadInfo(const activator_t *activator) :
thread_era { thinker_era },
mo{ nullptr },
line{ activator->line },
side{ activator->side },
@ -100,11 +104,15 @@ public:
~ThreadInfo()
{
P_SetTarget(&mo, nullptr);
if (thread_era == thinker_era)
{
P_SetTarget(&mo, nullptr);
}
}
ThreadInfo &operator = (const ThreadInfo &info)
{
thread_era = thinker_era;
P_SetTarget(&mo, info.mo);
line = info.line;
side = info.side;

View file

@ -79,6 +79,7 @@ typedef enum
extern thinker_t thlist[];
void P_InitThinkers(void);
void P_InvalidateThinkersWithoutInit(void);
void P_AddThinker(const thinklistnum_t n, thinker_t *thinker);
void P_RemoveThinker(thinker_t *thinker);
void P_UnlinkThinker(thinker_t *thinker);

View file

@ -53,6 +53,8 @@
tic_t leveltime;
boolean thinkersCompleted;
UINT32 thinker_era = 0;
static boolean g_freezeCheat;
static boolean g_freezeLevel;
@ -276,6 +278,8 @@ void P_InitThinkers(void)
{
UINT8 i;
P_InvalidateThinkersWithoutInit();
for (i = 0; i < NUM_THINKERLISTS; i++)
{
thlist[i].prev = thlist[i].next = &thlist[i];
@ -297,6 +301,15 @@ void P_InitThinkers(void)
Obj_ResetCheckpoints();
}
//
// P_InvalidateThinkersWithoutInit
//
void P_InvalidateThinkersWithoutInit(void)
{
thinker_era++;
}
// Adds a new thinker at the end of the list.
void P_AddThinker(const thinklistnum_t n, thinker_t *thinker)
{

View file

@ -43,6 +43,8 @@ void P_PreTicker(INT32 frames);
void P_DoTeamscrambling(void);
void P_RemoveThinkerDelayed(thinker_t *thinker); //killed
extern UINT32 thinker_era;
mobj_t *P_SetTarget2(mobj_t **mo, mobj_t *target
#ifdef PARANOIA
, const char *source_file, int source_line