mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
fix: #2635 NetworkIdentity.OnDestroy only clears NetworkClient.localPlayer if WE are STILL the local player.
fixes data race in rooms scene (explanation see comments)
This commit is contained in:
parent
2cd4403429
commit
457b21d907
@ -528,6 +528,27 @@ void OnDestroy()
|
||||
|
||||
if (isLocalPlayer)
|
||||
{
|
||||
// previously there was a bug where isLocalPlayer was
|
||||
// false in OnDestroy because it was dynamically defined as:
|
||||
// isLocalPlayer => NetworkClient.localPlayer == this
|
||||
// we fixed it by setting isLocalPlayer manually and never
|
||||
// resetting it.
|
||||
//
|
||||
// BUT now we need to be aware of a possible data race like in
|
||||
// our rooms example:
|
||||
// => GamePlayer is in world
|
||||
// => player returns to room
|
||||
// => GamePlayer is destroyed
|
||||
// => NetworkClient.localPlayer is set to RoomPlayer
|
||||
// => GamePlayer.OnDestroy is called 1 frame later
|
||||
// => GamePlayer.OnDestroy 'isLocalPlayer' is true, so here we
|
||||
// are trying to clear NetworkClient.localPlayer
|
||||
// => which would overwrite the new RoomPlayer local player
|
||||
//
|
||||
// FIXED by simply only clearing if NetworkClient.localPlayer
|
||||
// still points to US!
|
||||
// => see also: https://github.com/vis2k/Mirror/issues/2635
|
||||
if (NetworkClient.localPlayer == this)
|
||||
NetworkClient.ClearLocalPlayer();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user