Fix rare crash in K_SetRespawnAtNextWaypoint

This commit is contained in:
NepDisk 2025-04-22 22:21:17 -04:00
parent 39302801ad
commit e10af1eb70

View file

@ -8661,17 +8661,22 @@ static void K_FudgeRespawn(player_t *player, const waypoint_t *const waypoint)
void K_SetRespawnAtNextWaypoint(player_t * player)
{
mobj_t *currentwaypoint = player->currentwaypoint->mobj;
mobj_t *safewaypoint = player->nextwaypoint->mobj;
angle_t respawnangle = R_PointToAngle2(currentwaypoint->x, currentwaypoint->y, safewaypoint->x, safewaypoint->y);
mobj_t *currentwaypoint;
mobj_t *safewaypoint;
angle_t respawnangle;
// Safety :P
if (!safewaypoint || !currentwaypoint)
if (!player->currentwaypoint || !player->nextwaypoint)
{
// Better safe then sorry.
CONS_Alert(CONS_WARNING, M_GetText("Tried to respawn at invalid waypoint!\n"));
return;
}
currentwaypoint = player->currentwaypoint->mobj;
safewaypoint = player->nextwaypoint->mobj;
respawnangle = R_PointToAngle2(currentwaypoint->x, currentwaypoint->y, safewaypoint->x, safewaypoint->y);
player->pflags |= PF_TRUSTWAYPOINTS;
player->starposttime = player->realtime;
player->starpostz = (safewaypoint->spawnpoint->z + 15) >> FRACBITS;