Skip to content

Commit

Permalink
fix #923: move NetworkManager.OnApplicationQuit Transport Shutdown co…
Browse files Browse the repository at this point in the history
…de into Transport.OnApplicationQuit. Fixes a potential bug where the Transport wouldn't be shut down if someone doesn't use the NetworkManager.
  • Loading branch information
miwarnec committed Jan 9, 2020
1 parent 76a514a commit 2d59de8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 0 additions & 6 deletions Assets/Mirror/Runtime/NetworkManager.cs
Expand Up @@ -642,12 +642,6 @@ public virtual void OnApplicationQuit()
StopServer();
print("OnApplicationQuit: stopped server");
}

// stop transport (e.g. to shut down threads)
// (when pressing Stop in the Editor, Unity keeps threads alive
// until we press Start again. so if Transports use threads, we
// really want them to end now and not after next start)
Transport.activeTransport.Shutdown();
}

/// <summary>
Expand Down
13 changes: 13 additions & 0 deletions Assets/Mirror/Runtime/Transport/Transport.cs
Expand Up @@ -204,5 +204,18 @@ public virtual bool GetConnectionInfo(int connectionId, out string address)
// ShoulderRotation.LateUpdate, resulting in projectile
// spawns at the point before shoulder rotation.
public void Update() { }

/// <summary>
/// called when quitting the application by closing the window / pressing stop in the editor
/// <para>virtual so that inheriting classes' OnApplicationQuit() can call base.OnApplicationQuit() too</para>
/// </summary>
public virtual void OnApplicationQuit()
{
// stop transport (e.g. to shut down threads)
// (when pressing Stop in the Editor, Unity keeps threads alive
// until we press Start again. so if Transports use threads, we
// really want them to end now and not after next start)
Shutdown();
}
}
}

0 comments on commit 2d59de8

Please sign in to comment.