Add some checks to prevent invalid awayviewmobjs from crashing the game. Not fullproof but at the least the P_CameraThinker crash no longer happens

This commit is contained in:
Monster Iestyn 2018-12-11 18:38:35 +00:00
parent 1029463741
commit 582c5332f4
2 changed files with 10 additions and 3 deletions

View file

@ -3506,7 +3506,7 @@ boolean P_CameraThinker(player_t *player, camera_t *thiscam, boolean resetcalled
if (player->pflags & PF_FLIPCAM && !(player->pflags & PF_NIGHTSMODE) && player->mo->eflags & MFE_VERTICALFLIP) if (player->pflags & PF_FLIPCAM && !(player->pflags & PF_NIGHTSMODE) && player->mo->eflags & MFE_VERTICALFLIP)
postimg = postimg_flip; postimg = postimg_flip;
else if (player->awayviewtics && player->awayviewmobj != NULL) // Camera must obviously exist else if (player->awayviewtics && player->awayviewmobj && !P_MobjWasRemoved(player->awayviewmobj)) // Camera must obviously exist
{ {
camera_t dummycam; camera_t dummycam;
dummycam.subsector = player->awayviewmobj->subsector; dummycam.subsector = player->awayviewmobj->subsector;

View file

@ -8372,7 +8372,7 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall
if (!(multiplayer || netgame) && !splitscreen) if (!(multiplayer || netgame) && !splitscreen)
{ {
fixed_t vx = thiscam->x, vy = thiscam->y; fixed_t vx = thiscam->x, vy = thiscam->y;
if (player->awayviewtics && player->awayviewmobj != NULL) // Camera must obviously exist if (player->awayviewtics && player->awayviewmobj != NULL && !P_MobjWasRemoved(player->awayviewmobj)) // Camera must obviously exist
{ {
vx = player->awayviewmobj->x; vx = player->awayviewmobj->x;
vy = player->awayviewmobj->y; vy = player->awayviewmobj->y;
@ -8534,7 +8534,7 @@ static void P_CalcPostImg(player_t *player)
else else
pviewheight = player->mo->z + player->viewheight; pviewheight = player->mo->z + player->viewheight;
if (player->awayviewtics) if (player->awayviewtics && player->awayviewmobj && !P_MobjWasRemoved(player->awayviewmobj))
{ {
sector = player->awayviewmobj->subsector->sector; sector = player->awayviewmobj->subsector->sector;
pviewheight = player->awayviewmobj->z + 20*FRACUNIT; pviewheight = player->awayviewmobj->z + 20*FRACUNIT;
@ -8701,6 +8701,13 @@ void P_PlayerThink(player_t *player)
} }
} }
#endif #endif
if (player->awayviewmobj && P_MobjWasRemoved(player->awayviewmobj))
{
P_SetTarget(&player->awayviewmobj, NULL); // remove awayviewmobj asap if invalid
player->awayviewtics = 0; // reset to zero
}
if (player->pflags & PF_GLIDING) if (player->pflags & PF_GLIDING)
{ {
if (player->panim != PA_ABILITY) if (player->panim != PA_ABILITY)