offlineMode internal state bug

(Please note, in the following scenario, we never connect to the server. )

When we switch offlineMode to true, followed later by offlineMode to false, and then again offlineMode to true, an error occurs:

Can't start OFFLINE mode while connected!
UnityEngine.Debug:LogError(Object)
PhotonNetwork:set_offlineMode(Boolean) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:488)
OnlineSessionController:StartOfflineMode() (at Assets/Scripts/Behaviours/Controllers/OnlineSessionController.cs:149)
GameSessionController:InitGameSession() (at Assets/Scripts/Behaviours/Controllers/GameSessionController.cs:97)
ActivityController:StartSpecialGameMode() (at Assets/Scripts/Behaviours/Controllers/ActivityController.cs:163)
MainMenuUiBehaviour:OnMapSelect(String) (at Assets/Scripts/Behaviours/UI/MainMenuUiBehaviour.cs:284)
MapSelectUiBehaviour:OnButtonClick(Int32) (at Assets/Scripts/Behaviours/UI/MapSelectUiBehaviour.cs:45)
UnityEngine.EventSystems.EventSystem:Update()


The reason for this is pretty simple, but a small fix will be needed within PUN.

When setting offlineMode to true, the PhotonNetwork.connected property becomes "true".

Next, when setting offlineMode to false, the PhotonNetwork.connected property remains "true". I don't think this should be the case.

Finally, when attempting to set offlineMode to true again, the error occurs because Photon thinks that the game is currently connected to a server.

I managed to partially work around the problem by doing this:

PhotonNetwork.networkingPeer.State = ClientState.Disconnected;

However, that in itself causes an error (that I'm just ignoring), because Photon is not actually truly connected.
It does, however, reset PhotonNetwork.connected to false, which is what is needed prior to using offlineMode again.

Side note: if you were wondering about the slightly strange workflow of using offlineMode in this way, I'm happy to describe. Just didn't want to dump too much info here straight away.

Thanks for any help!

Comments

  • Hi @farflunggames,

    sorry for the late response and thanks for your bug report. I have taken a look into it and can confirm, that this is a unwanted behaviour which will be fixed with the next release. I'm glad that you have already found a solution for the problem.

    For anybody else who encounters the same problem, you can either use the solution above or the following: Therefore open the PhotonNetwork.cs script and navigate to the bool LeaveRoom(bool becomeInactive = true) function. Inside the offlineMode condition add the following code line: networkingPeer.State = ClientState.PeerCreated; [line: 2158]. After applying this fix, it should work again.
  • Thanks for the help!
  • Hi, we have version v2.9 PUN and the same issue occurrs. Is this a regression of this bug?
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @wassx,

    Thank you for choosing Photon!

    Is this a regression of this bug?

    This discussion was originally meant for PUN 1 or PUN Classic.
    We did not receive similar reports for PUN2.
    Are you saying this issue started to happen in 2.9 and wasn't there in 2.8 or it was always there in PUN2?

    Could you provide minimal 100% reproduction steps?
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @wassx,

    I forgot that 2.10 is the latest version.
    Did you try it yet?
  • wassx
    wassx
    edited May 2019
    Hi @JohnTube, thx for this quick reply.
    When our app starts, it immediately tries to connect to the master server. This could go wrong (no internet connection) or establish a connection. As a next step I want to go into the offline mode. So I call PhotonNetwork.disconnect() and PhotonNetwork.OfflineMode = true; There the issues occurs as the "IsConnected" in the setter of OfflineMode is still true.

    Haven't ried 2.10 for now. Will update asap.

    EDIT: tested with 2.10 and same issue occurs.
  • Hi @JohnTube, I found the issue.
    I was immediately calling PhotonNetwork.OfflineMode = true after disconnecting, but it was not guaranteed that the connection was already dropped. When I move the switch to Offlinemode to the OnDisconnected callback, it works without exceptions.
    Afterwards it makes sense to me. Just to mention one possible improvement: when I would be able to pass a callback when disconnection happened or that there was no connection and the callback is called as the disconnect procedure is done anyways. This would help me to ensure a completed disconnect without minding if there was a connection,...
    Thx!