Skip to content

Commit

Permalink
Merge branch 'develop' into fix/ilpp-stripping-and-coreclr-compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
NoelStephensUnity authored Jul 12, 2023
2 parents 1e44dfb + 9ca4efb commit 32ea9fd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
### Fixed

- Fixed issue where `NetworkObject.SpawnWithObservers` was not being honored for late joining clients. (#2623)
- Fixed issue where invoking `NetworkManager.Shutdown` multiple times, depending upon the timing, could cause an exception. (#2622)
- Fixed ILPP issues when using CoreCLR and for certain dedicated server builds. (#2614)

## Changed
Expand Down
10 changes: 8 additions & 2 deletions com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -942,10 +942,16 @@ public void Shutdown(bool discardMessageQueue = false)
if (IsServer || IsClient)
{
m_ShuttingDown = true;
MessageManager.StopProcessing = discardMessageQueue;
if (MessageManager != null)
{
MessageManager.StopProcessing = discardMessageQueue;
}
}

NetworkConfig.NetworkTransport.OnTransportEvent -= ConnectionManager.HandleNetworkEvent;
if (NetworkConfig != null && NetworkConfig.NetworkTransport != null)
{
NetworkConfig.NetworkTransport.OnTransportEvent -= ConnectionManager.HandleNetworkEvent;
}
}

// Ensures that the NetworkManager is cleaned up before OnDestroy is run on NetworkObjects and NetworkBehaviours when unloading a scene with a NetworkManager
Expand Down
21 changes: 21 additions & 0 deletions testproject/Assets/Tests/Runtime/NetworkManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Unity.Netcode.TestHelpers.Runtime;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.TestTools;

namespace TestProject.RuntimeTests
{
Expand Down Expand Up @@ -94,5 +95,25 @@ public void ValidateHostSettings()
Assert.IsTrue(m_NumberOfTimesInvoked == 1, $"OnClientConnectedCallback was invoked {m_NumberOfTimesInvoked} as opposed to just once!");
Assert.IsTrue(m_NetworkBehaviourIsServerWasSet, $"IsServer was not true when OnClientConnectedCallback was invoked!");
}

/// <summary>
/// Validate shutting down a second time does not cause an exception.
/// </summary>
[UnityTest]
public IEnumerator ValidateShutdown()
{
// Register for the server stopped notification so we know we have shutdown completely
m_ServerNetworkManager.OnServerStopped += M_ServerNetworkManager_OnServerStopped;
// Shutdown
m_ServerNetworkManager.Shutdown();
yield return s_DefaultWaitForTick;
}

private void M_ServerNetworkManager_OnServerStopped(bool obj)
{
m_ServerNetworkManager.OnServerStopped -= M_ServerNetworkManager_OnServerStopped;
// Verify that we can invoke shutdown again without an exception
m_ServerNetworkManager.Shutdown();
}
}
}

0 comments on commit 32ea9fd

Please sign in to comment.