Skip to content

refactor!: remove network dictionary & set, use native container in List, add tests #1149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2e1551a
refactor!: clean up network dictionary, use native containers
mattwalsh-unity Sep 8, 2021
371869d
readonly missing
mattwalsh-unity Sep 8, 2021
6e4ede6
added dirty list as native container
mattwalsh-unity Sep 8, 2021
eb7c24f
NetworkSet ported to native
mattwalsh-unity Sep 8, 2021
cf7707c
improved destroy
mattwalsh-unity Sep 9, 2021
5b52d11
remove set & dictionary
mattwalsh-unity Sep 13, 2021
9351b6d
list cleanup
mattwalsh-unity Sep 13, 2021
fcfa217
more tests
mattwalsh-unity Sep 14, 2021
4213ae8
lint cleanup
mattwalsh-unity Sep 14, 2021
9746836
Fixing NetworkList tests from throwing
andrews-unity Sep 14, 2021
34f4c23
cleanup improvements, nativeList for dirty event list
mattwalsh-unity Sep 14, 2021
a280d04
test cleanup
mattwalsh-unity Sep 14, 2021
b32f493
Merge branch 'develop' into refactor/simplify_collection_interfaces
mattwalsh-unity Sep 14, 2021
33df729
rounded out xtors in NetworkList
mattwalsh-unity Sep 14, 2021
161f10e
improved ienumerable, removed client writability
mattwalsh-unity Sep 14, 2021
c7d6301
header cleanup
mattwalsh-unity Sep 14, 2021
42566af
now -> index
mattwalsh-unity Sep 14, 2021
3c5f22c
Merge branch 'develop' into refactor/simplify_collection_interfaces
mattwalsh-unity Sep 14, 2021
e2b55a7
server -> client
mattwalsh-unity Sep 14, 2021
b3cffbf
Merge branch 'refactor/simplify_collection_interfaces' of github.com:…
mattwalsh-unity Sep 14, 2021
1b2c343
Merge branch 'develop' into refactor/simplify_collection_interfaces
mattwalsh-unity Sep 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ internal void HandleNetworkVariableDeltas(Stream stream, ulong clientId)
}
}

if (NetworkManager.IsServer && !NetworkVariableFields[i].CanClientWrite(clientId))
if (NetworkManager.IsServer)
{
// we are choosing not to fire an exception here, because otherwise a malicious client could use this to crash the server
if (NetworkManager.NetworkConfig.EnsureNetworkVariableLengthSafety)
Expand Down Expand Up @@ -824,5 +824,24 @@ protected NetworkObject GetNetworkObject(ulong networkId)
{
return NetworkManager.SpawnManager.SpawnedObjects.TryGetValue(networkId, out NetworkObject networkObject) ? networkObject : null;
}

public void OnDestroy()
{
// this seems odd to do here, but in fact especially in tests we can find ourselves
// here without having called InitializedVariables, which causes problems if any
// of those variables use native containers (e.g. NetworkList) as they won't be
// registered here and therefore won't be cleaned up.
//
// we should study to understand the initialization patterns
if (!m_VarInit)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, there is something weird on why - in tests anyway - we instantiate a NB band then ditch it before we ever call InitializeVariables. But regardless, we are now saying that Netvars need a chance to be disposed, and this ensures we don't skip any. There are certainly better ways to register the netvars than the scan in InitializeVariables which we can look at later which might eliminate the need for this

{
InitializeVariables();
}

for (int i = 0; i < NetworkVariableFields.Count; i++)
{
NetworkVariableFields[i].Dispose();
}
}
}
}
Loading