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
1414### Fixed
1515
1616- 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 )
1718
1819## Changed
1920
Original file line number Diff line number Diff line change @@ -942,10 +942,16 @@ public void Shutdown(bool discardMessageQueue = false)
942942 if ( IsServer || IsClient )
943943 {
944944 m_ShuttingDown = true ;
945- MessageManager . StopProcessing = discardMessageQueue ;
945+ if ( MessageManager != null )
946+ {
947+ MessageManager . StopProcessing = discardMessageQueue ;
948+ }
946949 }
947950
948- NetworkConfig . NetworkTransport . OnTransportEvent -= ConnectionManager . HandleNetworkEvent ;
951+ if ( NetworkConfig != null && NetworkConfig . NetworkTransport != null )
952+ {
953+ NetworkConfig . NetworkTransport . OnTransportEvent -= ConnectionManager . HandleNetworkEvent ;
954+ }
949955 }
950956
951957 // 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 44using Unity . Netcode . TestHelpers . Runtime ;
55using UnityEngine ;
66using UnityEngine . SceneManagement ;
7+ using UnityEngine . TestTools ;
78
89namespace TestProject . RuntimeTests
910{
@@ -94,5 +95,25 @@ public void ValidateHostSettings()
9495 Assert . IsTrue ( m_NumberOfTimesInvoked == 1 , $ "OnClientConnectedCallback was invoked { m_NumberOfTimesInvoked } as opposed to just once!") ;
9596 Assert . IsTrue ( m_NetworkBehaviourIsServerWasSet , $ "IsServer was not true when OnClientConnectedCallback was invoked!") ;
9697 }
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+ }
97118 }
98119}
You can’t perform that action at this time.
0 commit comments