PUN 2 seems to disconnect after creating offline / joining offline room

When i create an offline room, every once and a while pun fails to see that i'm in a room despite me getting the OnJoinedRoom callback. At least I believe that is what is occuring because all the below occurs after connecting to the offline room.

My LocalPlayer = -1 and none of the PropertyUpdateCallbacks are executed. For example OnPlayerPropertiesUpdate, and
OnRoomPropertiesUpdate.

Here is how i am creating a offline room.

        PhotonNetwork.OfflineMode = true;
        PhotonNetwork.CreateRoom(roomName, new RoomOptions {
            IsVisible = false,
            MaxPlayers = 1
        });

Comments

  • I believe this is a bug, it seems to happen seemingly randomly.
  • Is there any way to file an official bug report? This seems like a pretty large bug to me.

    If it's not a bug there might be something in the documentation / sample project that's not correct as this is where I am basing my code off of.

    Thanks in advance!
  • meatloaf
    meatloaf
    edited October 2018
    Here is an image showing that I do indeed join an room, with a joined connection state and get a -1 ActorNumber.

    I also have debug statements in both OnPlayerPropertiesUpdate & OnRoomPropertiesUpdate, neither of which are displaying.
        public void OnRoomPropertiesUpdate(Hashtable propertiesThatChanged) {
            Debug.Log("Room props received...");
        }
    
        public void OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps) {
            Debug.Log("Player props received...");
        }
    https://drive.google.com/file/d/1QfHK3d_j_X2R1nK-Ff6CzLqDyvD4nMXb/view?usp=sharing
  • meatloaf
    meatloaf
    edited October 2018
    Found this weird error along with this occurring, not sure if it's linked though.

    Uncaught exception in async net callback: Object reference not set to an instance of an object UnityEditor.AsyncHTTPClient:Done(State, Int32)
  • After a bunch of investigation it's look to me like there might be an issue with PhotonNetwork.IsConnectedAndReady I dont' believe that it is returning the correct value for when Photon is actually connected and ready.
  • meatloaf
    meatloaf
    edited October 2018
    So here is the actual bug.
    1. Call ConnectUsingSettings()
    2. Below occur before Photon has fully connected to Master!
    3. Set OfflineMode = true
    4. Create offline room using

      PhotonNetwork.CreateRoom(roomName, new RoomOptions { IsVisible = false, MaxPlayers = 1 });
    Photon will join room, but set ActorNumber = -1 and PropUpdate callbacks won't be fired.

    Having to wait for photon to finish connecting to master to start OfflineMode seems strange if this is intended behavior.
  • Hi @meatloaf,

    you can not use PhotonNetwork.OfflineMode = true; while connecting or being connected to Photon. It will log an error to the console and won't have any results under normal circumstances.

    If you use PhotonNetwork.ConnectUsingSettings() it will either start the connection process if StartOffline is disabled in the PhotonServerSettings (or in code) or trigger the OnConnectedToMaster callback directly if StartOffline is enabled in the PhotonServerSettings (or in code).

    If you are not connected and call PhotonNetwork.OfflineMode = true;, the OnConnectedToMaster callback will be called as well.

    It you still think that this might be a bug, please try to create a repro case and share it with us. I can't reproduce it with the 5 steps you have provided.
  • meatloaf
    meatloaf
    edited November 2018
    You are indeed correct I forgot one step.
    1. Call ConnectUsingSettings()
    2. Below occur before Photon has fully connected to Master!
    3. Disconnect from Photon using PhotonNetwork.Disconnect();
    4. Wait for Disconnect
    5. Set OfflineMode = true
    6. Create offline room using
      PhotonNetwork.CreateRoom(roomName, new RoomOptions {
      IsVisible = false,
      MaxPlayers = 1
      });
    This is why the offline error is never being called because technically I disconnect before I set OfflineMode = true
  • meatloaf
    meatloaf
    edited November 2018
    Created a sample project which demonstrates the issue and can reliably reproduce.

    Here is a screenshot

    https://drive.google.com/file/d/1Os-Gqoe1d936Hm6ZNlo6BdZkSMPbQVFa/view?usp=sharing

    There are also no logs in the console.

    Thanks in advance!

    Code for repo project is as follows. I just followed the repo steps above.
    	public Text text;
    
    	private void Update() {
    		text.text = 
    			$"State: {PhotonNetwork.NetworkClientState}\n" +
    			$"Offline Mode: {PhotonNetwork.OfflineMode}\n" +
    			$"Actor Number: {PhotonNetwork.LocalPlayer.ActorNumber}\n" +
    			$"Room Name: {PhotonNetwork.CurrentRoom}\n";
    
    	}
    
    	public void OnConnectButtonPressed() {
    		PhotonNetwork.ConnectUsingSettings();
    	}
    
    	public void OnDisconnectButtonPressed() {
    		PhotonNetwork.Disconnect();
    	}
    	
    	public override void OnDisconnected(DisconnectCause cause) {
    		PhotonNetwork.OfflineMode = true;
    		PhotonNetwork.CreateRoom("Single Player", new RoomOptions() {
    			IsVisible = false,
    			MaxPlayers = 1
    		});
    	}
  • meatloaf
    meatloaf
    edited November 2018
    Strangely even if I changeOnDisconnectButtonPressed() to either of the following I'm still able to reproduce the bug.
    	public void OnDisconnectButtonPressed() {
    		if (PhotonNetwork.IsConnected) {
    			PhotonNetwork.Disconnect();
    		}
    	}
    	public void OnDisconnectButtonPressed() {
    		if (PhotonNetwork.IsConnectedAndReady) {
    			PhotonNetwork.Disconnect();
    		}
    	}
    However if I change it to the below the bug seems to be resolved. This leads me to believe IsConnected & IsConnectedAndReady are not working correctly.
    	public void OnDisconnectButtonPressed() {
    		if (PhotonNetwork.NetworkClientState == ClientState.ConnectedToMasterserver) {
    			PhotonNetwork.Disconnect();
    		}
    	}
  • Would love to get some follow up on this to see what the issue might be.

    Thanks in advance!
  • Just found another case in which PhotonNetwork.IsConnectedAndReady is marked as true yet I get this error

    JoinRandomRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster.

    Isn't the point of IsConnectedAndReady to be able to check that it's ok to call operations like JoinRandomRoom?

    Thanks in advance!
  • I have tried the source code you provided but I sadly can't reproduce it. In my test, the Actor Number is always set correctly. I have also tried the alternative for OnDisconnectButtonPressed() with the same result.

    Isn't the point of IsConnectedAndReady to be able to check that it's ok to call operations like JoinRandomRoom?


    Basically yes, but IsConnectedAndReady is also true if the client is connected to the Name- or the GameServer. It isn't limited to the MasterServer. So if you want to make use of IsConnectedAndReady, you would have to make use of PhotonNetwork.NetworkingClient.Server, too. This one returns the current server the client is connected to.