Skip to content

Commit ad96174

Browse files
fix: Don't throw when shutting down a config-less manager (#1479)
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: Andrew Spiering <andrews@unity3d.com>
1 parent 9ad9d3d commit ad96174

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
@@ -1129,7 +1129,10 @@ internal void ShutdownInternal()
11291129
MessagingSystem = null;
11301130
}
11311131

1132-
NetworkConfig.NetworkTransport.OnTransportEvent -= HandleRawTransportPoll;
1132+
if (NetworkConfig?.NetworkTransport != null)
1133+
{
1134+
NetworkConfig.NetworkTransport.OnTransportEvent -= HandleRawTransportPoll;
1135+
}
11331136

11341137
if (SpawnManager != null)
11351138
{

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)