Skip to content

NetworkVariable and NetworkList throw NullReferenceException if modified during application quit #2705

@A1win

Description

@A1win

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

  1. Spawn NetworkObject A with a NetworkVariable attached to it.
  2. Spawn NetworkObject B with a NetworkList attached to it.
  3. Spawn NetworkObject C with an OnNetworkDespawn function that modifies the NetworkVariable of NetworkObject A.
  4. Spawn NetworkObject D with an OnNetworkDespawn function that modifies the NetworkList of NetworkObject B.
  5. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:highThis issue has high priority and we are focusing to resolve itstat:importedStatus - Issue is tracked internally at Unitytype:bugBug Report

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions