Skip to content

Commit

Permalink
Clear tmthing at tic end
Browse files Browse the repository at this point in the history
Causes [rare?] crash when changing levels. Thanks to @WalesGaming of
Twitter for reporting this!
  • Loading branch information
bradharding committed Jul 19, 2014
1 parent 3016ea9 commit 53974b4
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/g_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ boolean G_Responder(event_t *ev)
&& ev->data1 != KEY_NUMLOCK
&& (ev->data1 < KEY_F1 || ev->data1 > KEY_F12))
|| (ev->type == ev_mouse
&& (ev->data1 && !(ev->data1 & MOUSE_WHEELUP || ev->data1 & MOUSE_WHEELDOWN)))
&& (ev->data1 && !(ev->data1 & (MOUSE_WHEELUP | MOUSE_WHEELDOWN))))
|| (ev->type == ev_gamepad
&& gamepadwait < I_GetTime()
&& gamepadbuttons
Expand Down Expand Up @@ -812,11 +812,15 @@ void G_Ticker(void)
int buf;
ticcmd_t *cmd;

P_MapStart();

// do player reborns if needed
for (i = 0; i < MAXPLAYERS; i++)
if (playeringame[i] && players[i].playerstate == PST_REBORN)
G_DoReborn(i);

P_MapEnd();

// do things to change the game state
while (gameaction != ga_nothing)
{
Expand Down Expand Up @@ -1549,12 +1553,16 @@ void G_DoLoadGame(void)

leveltime = savedleveltime;

P_MapStart();

// dearchive all the modifications
P_UnArchivePlayers();
P_UnArchiveWorld();
P_UnArchiveThinkers();
P_UnArchiveSpecials();

P_MapEnd();

if (!P_ReadSaveGameEOF())
I_Error("Bad savegame");

Expand Down
3 changes: 3 additions & 0 deletions src/p_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ void P_RadiusAttack(mobj_t *spot, mobj_t *source, int damage);

void P_ApplyTorque(mobj_t *mo); // killough 9/12/98

void P_MapStart(void);
void P_MapEnd(void);

//
// P_SETUP
//
Expand Down
16 changes: 16 additions & 0 deletions src/p_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ along with DOOM RETRO. If not, see http://www.gnu.org/licenses/.
#include <stdlib.h>

#include "doomstat.h"
#include "i_system.h"
#include "m_bbox.h"
#include "m_random.h"
#include "p_local.h"
Expand Down Expand Up @@ -2057,3 +2058,18 @@ void P_CreateSecNodeList(mobj_t *thing, fixed_t x, fixed_t y)
tmbbox[BOXLEFT] = tmx - tmthing->radius;
}
}

// cphipps 2004/08/30 -
// Must clear tmthing at tic end, as it might contain a pointer to a removed
// thinker, or the level might have ended/been ended and we clear the objects it
// was pointing to. Hopefully we don't need to carry this between tics for sync.
void P_MapStart(void)
{
if (tmthing)
I_Error("P_MapStart: tmthing set!");
}

void P_MapEnd(void)
{
tmthing = NULL;
}
4 changes: 4 additions & 0 deletions src/p_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,8 @@ void P_SetupLevel(int episode, int map)
bloodSplatQueueSlot = 0;
memset(bloodSplatQueue, 0, sizeof(mobj_t *) * bloodsplats);

P_MapStart();

P_LoadThings(lumpnum + ML_THINGS);

P_InitCards(&players[0]);
Expand All @@ -1124,6 +1126,8 @@ void P_SetupLevel(int episode, int map)
// set up world state
P_SpawnSpecials();

P_MapEnd();

// preload graphics
R_PrecacheLevel();
}
Expand Down
13 changes: 9 additions & 4 deletions src/p_tick.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,22 @@ void P_Ticker(void)
return;

// pause if in menu and at least one tic has been run
if (!netgame && menuactive && players[consoleplayer].viewz != 1)
if (!netgame && menuactive && players[consoleplayer].viewz != 1)
return;

for (i = 0; i < MAXPLAYERS; i++)
if (playeringame[i])
P_PlayerThink(&players[i]);
P_MapStart();

if (gamestate == GS_LEVEL)
for (i = 0; i < MAXPLAYERS; i++)
if (playeringame[i])
P_PlayerThink(&players[i]);

P_RunThinkers();
P_UpdateSpecials();
P_RespawnSpecials();

P_MapEnd();

// for par times
leveltime++;
}

4 comments on commit 53974b4

@fabiangreffrath
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this also affect chocolate-doom or is it necessary because of another change you introduced into DR?

@bradharding
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this would be due to the major changes I made p_map.c: the complete rewrite of P_ChangeSector() and the addition of secnode functions following that (commit a8aa7f7).
Specifically, this commit stopped DR from crashing when ending MAP01 in BTSX_E1.WAD.

@fabiangreffrath
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the changes to p_map.c were necessary to fix a problem in HR.WAD and even a crash in BTSX?

@bradharding
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Commit a8aa7f7 fixed the problem in HR.WAD (as described in issue #9), but without the addition of the changes in this commit also, caused crashes when switching to some levels (as was reported to happen in BTSX). I think. 😁

Please sign in to comment.