Correct order of Destroy in RemovePlayer (#262)

The RemovePlayerController call sets the playerController to null, causing a null dereference  (and a memory leak as pointed out by @paulpach, since gameobjects are never destroyed)
This commit is contained in:
Robin Rolf 2019-01-08 22:12:17 +01:00 committed by vis2k
parent eaa506fb26
commit c490d9faa0
2 changed files with 3 additions and 2 deletions

View File

@ -121,10 +121,11 @@ public static bool RemovePlayer()
RemovePlayerMessage msg = new RemovePlayerMessage();
s_ReadyConnection.Send((short)MsgType.RemovePlayer, msg);
Object.Destroy(s_ReadyConnection.playerController.gameObject);
s_ReadyConnection.RemovePlayerController();
s_LocalPlayer = null;
Object.Destroy(s_ReadyConnection.playerController.gameObject);
return true;
}
return false;

View File

@ -821,8 +821,8 @@ static void OnRemovePlayerMessage(NetworkMessage netMsg)
{
if (netMsg.conn.playerController != null)
{
netMsg.conn.RemovePlayerController();
Destroy(netMsg.conn.playerController.gameObject);
netMsg.conn.RemovePlayerController();
}
else
{