Fixed a rare crash that happened when retrieving a player's old camera when they respawned.
On rare occasions in offline games, this line in P_SpawnPlayer
would cause the game to crash:
AActor *oldCamera = ( NETWORK_GetState( ) != NETSTATE_SERVER ) ? p->camera : nullptr;
This was because p->camera
was an invalid pointer. However, changing the line to this seems to fix the crash:
AActor *oldCamera = (( NETWORK_GetState( ) != NETSTATE_SERVER ) && ( p == &players[consoleplayer] )) ? p->camera : nullptr;
It appears that in some cases, p->camera
may be an invalid pointer, but only for other players besides the local player. Since oldCamera
is only used to restore the local player's view anyways, we might as well ensure that it can only be used to retrieve the local player's camera, and a null pointer otherwise.