Skip to content

Commit f3ddcb8

Browse files
fix: Don't throw when shutting down a config-less manager (#1504)
If shutting down a NetworkManager that doesn't have a NetworkConfig, it would throw when trying to remove the OnTransportEvent delegate from the transport. Co-authored-by: Fatih Mar <[email protected]>
1 parent efc70f8 commit f3ddcb8

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,10 @@ internal void ShutdownInternal()
10961096
MessagingSystem = null;
10971097
}
10981098

1099-
NetworkConfig.NetworkTransport.OnTransportEvent -= HandleRawTransportPoll;
1099+
if (NetworkConfig?.NetworkTransport != null)
1100+
{
1101+
NetworkConfig.NetworkTransport.OnTransportEvent -= HandleRawTransportPoll;
1102+
}
11001103

11011104
if (SpawnManager != null)
11021105
{

com.unity.netcode.gameobjects/Tests/Editor/StartStopTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ public void TestFlagShutdown()
5252
Assert.False(m_NetworkManager.IsHost);
5353
}
5454

55+
[Test]
56+
public void TestShutdownWithoutStartForExceptions()
57+
{
58+
m_NetworkManager.ShutdownInternal();
59+
}
60+
61+
[Test]
62+
public void TestShutdownWithoutConfigForExceptions()
63+
{
64+
m_NetworkManager.NetworkConfig = null;
65+
m_NetworkManager.ShutdownInternal();
66+
}
67+
5568
[TearDown]
5669
public void Teardown()
5770
{

0 commit comments

Comments
 (0)