fix: #3392 NetworkLoop now checks if the function was already added before. fixes functions being added twice with Domain Reload disabled.

This commit is contained in:
vis2k 2023-03-04 19:29:33 +08:00
parent 91014bd614
commit 8f66bd68ca

View File

@ -99,6 +99,15 @@ internal static bool AddToPlayerLoop(PlayerLoopSystem.UpdateFunction function, T
//foreach (PlayerLoopSystem sys in playerLoop.subSystemList) //foreach (PlayerLoopSystem sys in playerLoop.subSystemList)
// Debug.Log($" ->{sys.type}"); // Debug.Log($" ->{sys.type}");
// make sure the function wasn't added yet.
// with domain reload disabled, it would otherwise be added twice:
// fixes: https://github.com/MirrorNetworking/Mirror/issues/3392
if (Array.FindIndex(playerLoop.subSystemList, (s => s.updateDelegate == function)) != -1)
{
// loop contains the function, so return true.
return true;
}
// resize & expand subSystemList to fit one more entry // resize & expand subSystemList to fit one more entry
int oldListLength = (playerLoop.subSystemList != null) ? playerLoop.subSystemList.Length : 0; int oldListLength = (playerLoop.subSystemList != null) ? playerLoop.subSystemList.Length : 0;
Array.Resize(ref playerLoop.subSystemList, oldListLength + 1); Array.Resize(ref playerLoop.subSystemList, oldListLength + 1);