File tree Expand file tree Collapse file tree 3 files changed +30
-2
lines changed
com.unity.netcode.gameobjects
testproject/Assets/Tests/Runtime Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
14
14
### Fixed
15
15
16
16
- Fixed issue where ` NetworkObject.SpawnWithObservers ` was not being honored for late joining clients. (#2623 )
17
+ - Fixed issue where invoking ` NetworkManager.Shutdown ` multiple times, depending upon the timing, could cause an exception. (#2622 )
17
18
18
19
## Changed
19
20
Original file line number Diff line number Diff line change @@ -942,10 +942,16 @@ public void Shutdown(bool discardMessageQueue = false)
942
942
if ( IsServer || IsClient )
943
943
{
944
944
m_ShuttingDown = true ;
945
- MessageManager . StopProcessing = discardMessageQueue ;
945
+ if ( MessageManager != null )
946
+ {
947
+ MessageManager . StopProcessing = discardMessageQueue ;
948
+ }
946
949
}
947
950
948
- NetworkConfig . NetworkTransport . OnTransportEvent -= ConnectionManager . HandleNetworkEvent ;
951
+ if ( NetworkConfig != null && NetworkConfig . NetworkTransport != null )
952
+ {
953
+ NetworkConfig . NetworkTransport . OnTransportEvent -= ConnectionManager . HandleNetworkEvent ;
954
+ }
949
955
}
950
956
951
957
// Ensures that the NetworkManager is cleaned up before OnDestroy is run on NetworkObjects and NetworkBehaviours when unloading a scene with a NetworkManager
Original file line number Diff line number Diff line change 4
4
using Unity . Netcode . TestHelpers . Runtime ;
5
5
using UnityEngine ;
6
6
using UnityEngine . SceneManagement ;
7
+ using UnityEngine . TestTools ;
7
8
8
9
namespace TestProject . RuntimeTests
9
10
{
@@ -94,5 +95,25 @@ public void ValidateHostSettings()
94
95
Assert . IsTrue ( m_NumberOfTimesInvoked == 1 , $ "OnClientConnectedCallback was invoked { m_NumberOfTimesInvoked } as opposed to just once!") ;
95
96
Assert . IsTrue ( m_NetworkBehaviourIsServerWasSet , $ "IsServer was not true when OnClientConnectedCallback was invoked!") ;
96
97
}
98
+
99
+ /// <summary>
100
+ /// Validate shutting down a second time does not cause an exception.
101
+ /// </summary>
102
+ [ UnityTest ]
103
+ public IEnumerator ValidateShutdown ( )
104
+ {
105
+ // Register for the server stopped notification so we know we have shutdown completely
106
+ m_ServerNetworkManager . OnServerStopped += M_ServerNetworkManager_OnServerStopped ;
107
+ // Shutdown
108
+ m_ServerNetworkManager . Shutdown ( ) ;
109
+ yield return s_DefaultWaitForTick ;
110
+ }
111
+
112
+ private void M_ServerNetworkManager_OnServerStopped ( bool obj )
113
+ {
114
+ m_ServerNetworkManager . OnServerStopped -= M_ServerNetworkManager_OnServerStopped ;
115
+ // Verify that we can invoke shutdown again without an exception
116
+ m_ServerNetworkManager . Shutdown ( ) ;
117
+ }
97
118
}
98
119
}
You can’t perform that action at this time.
0 commit comments