Description
When Shutdown() is called on the server during Application Quit and a NetworkObject's OnNetworkDespawn causes a different NetworkObject to modify a NetworkList or NetworkVariable that's attached to it, a NullReferenceException is thrown.
For NetworkList.cs, the exception gets thrown in the MarkNetworkObjectDirty function on line 78.
For NetworkVariableBase.cs, it gets thrown on SetDirty function on line 98.
This is an edge case of #2606 that was fixed in Netcode 1.5.2. Previously, this error always occurred during Shutdown() even if the shutdown was not caused by application quit.
As a less than ideal workaround, it seems to be possible to check for NetworkManager.ShutdownInProgress before making modifications to NetworkVariables or NetworkLists during application quit.
Reproduce Steps
- Spawn NetworkObject A with a
NetworkVariable attached to it.
- Spawn NetworkObject B with a
NetworkList attached to it.
- Spawn NetworkObject C with an
OnNetworkDespawn function that modifies the NetworkVariable of NetworkObject A.
- Spawn NetworkObject D with an
OnNetworkDespawn function that modifies the NetworkList of NetworkObject B.
- Quit the application as the server (or exit play mode in the Editor), causing a shutdown. Notice errors thrown by
NetworkVariableBase.cs and NetworkList.cs.
I'm not sure if this is a reliable way to reproduce the issue and I don't currently have a small sample project to reproduce it in.
Actual Outcome
NetworkVariableBase and NetworkList throw a NullReferenceException when modified during application quit.
Expected Outcome
No exceptions are thrown when modifying a NetworkVariable or a NetworkList during application quit.
Environment
- OS: Windows 10
- Unity Version:
2022.3.7f1
- Netcode Version:
1.5.2
- Netcode Commit: 3636884
Description
When
Shutdown()is called on the server during Application Quit and a NetworkObject'sOnNetworkDespawncauses a different NetworkObject to modify aNetworkListorNetworkVariablethat's attached to it, aNullReferenceExceptionis thrown.For
NetworkList.cs, the exception gets thrown in theMarkNetworkObjectDirtyfunction on line78.For
NetworkVariableBase.cs, it gets thrown onSetDirtyfunction on line98.This is an edge case of #2606 that was fixed in Netcode
1.5.2. Previously, this error always occurred duringShutdown()even if the shutdown was not caused by application quit.As a less than ideal workaround, it seems to be possible to check for
NetworkManager.ShutdownInProgressbefore making modifications to NetworkVariables or NetworkLists during application quit.Reproduce Steps
NetworkVariableattached to it.NetworkListattached to it.OnNetworkDespawnfunction that modifies theNetworkVariableof NetworkObject A.OnNetworkDespawnfunction that modifies theNetworkListof NetworkObject B.NetworkVariableBase.csandNetworkList.cs.I'm not sure if this is a reliable way to reproduce the issue and I don't currently have a small sample project to reproduce it in.
Actual Outcome
NetworkVariableBase and NetworkList throw a NullReferenceException when modified during application quit.
Expected Outcome
No exceptions are thrown when modifying a NetworkVariable or a NetworkList during application quit.
Environment
2022.3.7f11.5.2