Skip to content

Commit db6de50

Browse files
refactor!: remove network dictionary & set, use native container in List, add tests (#1149)
* refactor!: clean up network dictionary, use native containers * added dirty list as native container * remove set & dictionary * list cleanup * more tests * rounded out xtors in NetworkList * improved ienumerable, removed client writability Co-authored-by: Andrew Spiering <andrews@unity3d.com>
1 parent 4e3880f commit db6de50

File tree

11 files changed

+173
-1222
lines changed

11 files changed

+173
-1222
lines changed

com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ internal void HandleNetworkVariableDeltas(Stream stream, ulong clientId)
639639
}
640640
}
641641

642-
if (NetworkManager.IsServer && !NetworkVariableFields[i].CanClientWrite(clientId))
642+
if (NetworkManager.IsServer)
643643
{
644644
// we are choosing not to fire an exception here, because otherwise a malicious client could use this to crash the server
645645
if (NetworkManager.NetworkConfig.EnsureNetworkVariableLengthSafety)
@@ -824,5 +824,24 @@ protected NetworkObject GetNetworkObject(ulong networkId)
824824
{
825825
return NetworkManager.SpawnManager.SpawnedObjects.TryGetValue(networkId, out NetworkObject networkObject) ? networkObject : null;
826826
}
827+
828+
public void OnDestroy()
829+
{
830+
// this seems odd to do here, but in fact especially in tests we can find ourselves
831+
// here without having called InitializedVariables, which causes problems if any
832+
// of those variables use native containers (e.g. NetworkList) as they won't be
833+
// registered here and therefore won't be cleaned up.
834+
//
835+
// we should study to understand the initialization patterns
836+
if (!m_VarInit)
837+
{
838+
InitializeVariables();
839+
}
840+
841+
for (int i = 0; i < NetworkVariableFields.Count; i++)
842+
{
843+
NetworkVariableFields[i].Dispose();
844+
}
845+
}
827846
}
828847
}

0 commit comments

Comments
 (0)