mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
fix: Prevent recursion overflow when stopping (#2833)
* fix: Prevent recursion overflow when stopping Calling StopServer from OnStartServer or StopClient from OnStopClient (or from user code invoked from those virtual methods) would create a recursion overflow. This PR moves the setting of `isNetworkActive = false;` up above the virtual method calls in both cases, and adds a check to early out if false to prevent recursion and overflow. Debug logs were also moved up nearer the top of the method. Fixes: #2080 * Update Assets/Mirror/Runtime/NetworkManager.cs * Update Assets/Mirror/Runtime/NetworkManager.cs Co-authored-by: vis2k <info@noobtuts.com>
This commit is contained in:
parent
8453a03bd4
commit
32fdd5215f
@ -532,9 +532,12 @@ public void StopHost()
|
||||
/// <summary>Stops the server from listening and simulating the game.</summary>
|
||||
public void StopServer()
|
||||
{
|
||||
if (!NetworkServer.active)
|
||||
// return if already stopped to avoid recursion deadlock
|
||||
if (!isNetworkActive)
|
||||
return;
|
||||
|
||||
//Debug.Log("NetworkManager StopServer");
|
||||
|
||||
if (authenticator != null)
|
||||
{
|
||||
authenticator.OnServerAuthenticated.RemoveListener(OnServerAuthenticated);
|
||||
@ -553,10 +556,10 @@ public void StopServer()
|
||||
SceneManager.MoveGameObjectToScene(gameObject, SceneManager.GetActiveScene());
|
||||
#pragma warning restore 618
|
||||
|
||||
isNetworkActive = false;
|
||||
|
||||
OnStopServer();
|
||||
|
||||
//Debug.Log("NetworkManager StopServer");
|
||||
isNetworkActive = false;
|
||||
NetworkServer.Shutdown();
|
||||
|
||||
// set offline mode BEFORE changing scene so that FinishStartScene
|
||||
@ -576,6 +579,12 @@ public void StopServer()
|
||||
/// <summary>Stops and disconnects the client.</summary>
|
||||
public void StopClient()
|
||||
{
|
||||
// return if already stopped to avoid recursion deadlock
|
||||
if (!isNetworkActive)
|
||||
return;
|
||||
|
||||
//Debug.Log("NetworkManager StopClient");
|
||||
|
||||
if (authenticator != null)
|
||||
{
|
||||
authenticator.OnClientAuthenticated.RemoveListener(OnClientAuthenticated);
|
||||
@ -594,11 +603,10 @@ public void StopClient()
|
||||
SceneManager.MoveGameObjectToScene(gameObject, SceneManager.GetActiveScene());
|
||||
#pragma warning restore 618
|
||||
|
||||
OnStopClient();
|
||||
|
||||
//Debug.Log("NetworkManager StopClient");
|
||||
isNetworkActive = false;
|
||||
|
||||
OnStopClient();
|
||||
|
||||
// shutdown client
|
||||
NetworkClient.Disconnect();
|
||||
NetworkClient.Shutdown();
|
||||
|
Loading…
Reference in New Issue
Block a user