Search Unity

Game completely freezing when disconnecting client.

Discussion in 'Multiplayer' started by Chris_Entropy, Oct 8, 2015.

  1. Chris_Entropy

    Chris_Entropy

    Joined:
    Apr 11, 2011
    Posts:
    202
    Hi, I am using the NetworkLobbyManager as a basis and I am having a strange error when disconnecting a client while mid-game.
    The lobby setup, match browsing and joining works fine. I then set all clients ready to start the game, which also works and the game scene is loaded automatically. When I stop the server (end the build or stop the editor), all clients are thrown back into the lobby menu scene, as intended. If I stop the client (currently testing with only one client), the build running the server completely freezes and stops responding. This even happens in the Editor, which means I have to kill the editor via task manager.
    Another strange thing is that the Game Player Prefab is instantiated, but it does not fire any of its events. Am I missing something fundamental?
     
  2. SpeakUpGames

    SpeakUpGames

    Joined:
    Nov 25, 2014
    Posts:
    56
    Is it possible there is an infinite loop or something running in a client exit callback, such as OnLobbyServerDisconnect?
    As for the second case, if you mean UI events your game scene may not have a UI eventsystem.
     
  3. Chris_Entropy

    Chris_Entropy

    Joined:
    Apr 11, 2011
    Posts:
    202
    Ok, I think I pinpointed it, because ok your tip @SpeakUpGames , but I don't fully understand it yet.
    I have the followinf function in my Lobby Player Object (the class extends the Unity NetworkLobbyPlayer):

    Code (CSharp):
    1.     public override void OnNetworkDestroy ()
    2.     {
    3.         Debug.Log ("Destroying network object: playerControllerId: " + playerControllerId + ", isLocalPlayer: " + isLocalPlayer);
    4.         if (!isLocalPlayer && !readyToBegin && isServer) {
    5.             Debug.Log ("Leaving Player is local player.");
    6.             UnregisterPlayer();
    7.         }
    8.  
    9.     }
    10.  
    an this code in my In Game Player Object (the class extends from NetworkBehaviour):

    Code (CSharp):
    1.     public override void OnNetworkDestroy ()
    2.     {
    3.         Debug.Log ("Destroying network object: playerControllerId: " + playerControllerId + ", isLocalPlayer: " + isLocalPlayer);
    4.         if (!isLocalPlayer && isServer) {
    5.             Debug.Log ("Leaving Player is local player.");
    6.             if (NetworkLobbyManager_Custom.UncheckedInstance()) {
    7.                 NetworkLobbyManager_Custom.Instance ().SendReturnToLobby ();
    8.             }
    9.         }
    10.  
    11.     }
    12.  
    I think the Problem is, that there is already some kind of calllback, which triggers "SendReturnToLobby" in the Lobby object, which is then called twice and produces the error. I assume this, since the client is sent to the lobby automatically once the server quits, which is intended behaviour, but I never wrote any code for this to happen. So it has to be already implemented either in NetworkLobbyPlayer, which I am extending, or NetworkLobbyManager, which I am using as well.

    tl;dr: I commented the line NetworkLobbyManager_Custom.Instance ().SendReturnToLobby (); out. Now it no longer freezes. Thanks for your help, @SpeakUpGames
     
  4. _Adriaan

    _Adriaan

    Joined:
    Nov 12, 2009
    Posts:
    481
    Just to confirm: when I call NetworkManager.Shutdown() from the OnStopClient() method, the editor also freezes ;)
     
  5. Chris_Entropy

    Chris_Entropy

    Joined:
    Apr 11, 2011
    Posts:
    202
    I think that Networkmanager.Shutdown() again calls OnStopClient, which would lead to the endless loop. It would help, if we knew, what was going on in the NetworkManager and NetworkLobbyManager classes.
     
  6. _Adriaan

    _Adriaan

    Joined:
    Nov 12, 2009
    Posts:
    481
    (Completely off the record: you can decompile the Unity.Networking.dll file that comes with Unity using ILSpy. That'll give you insight into how the NetworkManager & NetworkLobbyManager work in the background exactly. The Unity Networking team is working on making the HLAPI open source soon, so this is definitely a good temporary option.)