fix: #2842 Revert "fix: Prevent recursion overflow when stopping (#2833)"

This reverts commit 32fdd5215f.
This commit is contained in:
vis2k 2021-07-20 11:40:29 +08:00
parent c3bd1f2798
commit 24033c101b

View File

@ -532,12 +532,9 @@ public void StopHost()
/// <summary>Stops the server from listening and simulating the game.</summary> /// <summary>Stops the server from listening and simulating the game.</summary>
public void StopServer() public void StopServer()
{ {
// return if already stopped to avoid recursion deadlock if (!NetworkServer.active)
if (!isNetworkActive)
return; return;
//Debug.Log("NetworkManager StopServer");
if (authenticator != null) if (authenticator != null)
{ {
authenticator.OnServerAuthenticated.RemoveListener(OnServerAuthenticated); authenticator.OnServerAuthenticated.RemoveListener(OnServerAuthenticated);
@ -556,10 +553,10 @@ public void StopServer()
SceneManager.MoveGameObjectToScene(gameObject, SceneManager.GetActiveScene()); SceneManager.MoveGameObjectToScene(gameObject, SceneManager.GetActiveScene());
#pragma warning restore 618 #pragma warning restore 618
isNetworkActive = false;
OnStopServer(); OnStopServer();
//Debug.Log("NetworkManager StopServer");
isNetworkActive = false;
NetworkServer.Shutdown(); NetworkServer.Shutdown();
// set offline mode BEFORE changing scene so that FinishStartScene // set offline mode BEFORE changing scene so that FinishStartScene
@ -579,12 +576,6 @@ public void StopServer()
/// <summary>Stops and disconnects the client.</summary> /// <summary>Stops and disconnects the client.</summary>
public void StopClient() public void StopClient()
{ {
// return if already stopped to avoid recursion deadlock
if (!isNetworkActive)
return;
//Debug.Log("NetworkManager StopClient");
if (authenticator != null) if (authenticator != null)
{ {
authenticator.OnClientAuthenticated.RemoveListener(OnClientAuthenticated); authenticator.OnClientAuthenticated.RemoveListener(OnClientAuthenticated);
@ -603,10 +594,11 @@ public void StopClient()
SceneManager.MoveGameObjectToScene(gameObject, SceneManager.GetActiveScene()); SceneManager.MoveGameObjectToScene(gameObject, SceneManager.GetActiveScene());
#pragma warning restore 618 #pragma warning restore 618
isNetworkActive = false;
OnStopClient(); OnStopClient();
//Debug.Log("NetworkManager StopClient");
isNetworkActive = false;
// shutdown client // shutdown client
NetworkClient.Disconnect(); NetworkClient.Disconnect();
NetworkClient.Shutdown(); NetworkClient.Shutdown();