From 582c5332f44e4b8547f3b43ed59a9a87406a5023 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 11 Dec 2018 18:38:35 +0000 Subject: [PATCH] Add some checks to prevent invalid awayviewmobjs from crashing the game. Not fullproof but at the least the P_CameraThinker crash no longer happens --- src/p_mobj.c | 2 +- src/p_user.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 8811308a7..4fea15802 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -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) 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; dummycam.subsector = player->awayviewmobj->subsector; diff --git a/src/p_user.c b/src/p_user.c index cf1296694..906167548 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -8372,7 +8372,7 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall if (!(multiplayer || netgame) && !splitscreen) { 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; vy = player->awayviewmobj->y; @@ -8534,7 +8534,7 @@ static void P_CalcPostImg(player_t *player) else pviewheight = player->mo->z + player->viewheight; - if (player->awayviewtics) + if (player->awayviewtics && player->awayviewmobj && !P_MobjWasRemoved(player->awayviewmobj)) { sector = player->awayviewmobj->subsector->sector; pviewheight = player->awayviewmobj->z + 20*FRACUNIT; @@ -8701,6 +8701,13 @@ void P_PlayerThink(player_t *player) } } #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->panim != PA_ABILITY)