- Fixed: Loading a multiplayer save with only one player crashed.

SVN r1319 (trunk)
This commit is contained in:
Randy Heit 2008-12-16 03:59:28 +00:00
parent 4c14c197f8
commit 86c04f6b82

View file

@ -147,7 +147,7 @@ static void ReadMultiplePlayers (FArchive &arc, int numPlayers, int numPlayersNo
char **nametemp = new char *[numPlayers]; char **nametemp = new char *[numPlayers];
player_t *playertemp = new player_t[numPlayers]; player_t *playertemp = new player_t[numPlayers];
BYTE *tempPlayerUsed = new BYTE[numPlayers]; BYTE *tempPlayerUsed = new BYTE[numPlayers];
BYTE *playerUsed = new BYTE[MAXPLAYERS]; BYTE playerUsed[MAXPLAYERS];
for (i = 0; i < numPlayers; ++i) for (i = 0; i < numPlayers; ++i)
{ {
@ -202,7 +202,9 @@ static void ReadMultiplePlayers (FArchive &arc, int numPlayers, int numPlayersNo
} }
} }
// Make sure any extra players don't have actors spawned yet. // Make sure any extra players don't have actors spawned yet. Happens if the players
// present now got the same slots as they had in the save, but there are not as many
// as there were in the save.
for (j = 0; j < MAXPLAYERS; ++j) for (j = 0; j < MAXPLAYERS; ++j)
{ {
if (playerUsed[j] == 0) if (playerUsed[j] == 0)
@ -214,9 +216,19 @@ static void ReadMultiplePlayers (FArchive &arc, int numPlayers, int numPlayersNo
} }
} }
} }
// Remove any temp players that were not used. Happens if there are fewer players
// than there were in the save, and they got shuffled.
for (i = 0; i < numPlayers; ++i)
{
if (tempPlayerUsed[i] == 0)
{
playertemp[i].mo->Destroy();
playertemp[i].mo = NULL;
}
}
} }
delete[] playerUsed;
delete[] tempPlayerUsed; delete[] tempPlayerUsed;
delete[] playertemp; delete[] playertemp;
for (i = 0; i < numPlayers; ++i) for (i = 0; i < numPlayers; ++i)
@ -253,6 +265,11 @@ static void CopyPlayer (player_t *dst, player_t *src, const char *name)
{ {
dst->userinfo = uibackup; dst->userinfo = uibackup;
} }
// Make sure the player pawn points to the proper player struct.
if (dst->mo != NULL)
{
dst->mo->player = dst;
}
} }
static void SpawnExtraPlayers () static void SpawnExtraPlayers ()