Late joining Bug!!!

Options
in recent versions of PUN, a new bug is found in changing master client. consider this scenario:
1. actor 1 creates a room. scene has a GO with photonView that is owned by scene. so master client (actor 1) can controll it (photonView.isMine == true).
2. actor 2 joins the room. the GO photonView ownerId changed from 0 to 1 (due to feature LATE JOINING located in NetworkingPeer.cs line 4108)
3. masterClient changed from 1 to 2 on calling`PhotonNetwork.SetMasterClient()` by actor 1 or when actor 1 is inactive. now the GO photonView is not controlled by anyone. photonView.isMine == false for both actor. (the GO photonView ownerId that was changed to 1, will be kept 1 and not changed to 0).

If i commend LATE JOINING feature (NetworkingPeer.cs line 4108), all will be OK.

Best Answer

Answers

  • [Deleted User]
    edited November 2016
    Options
    Hi ahoogol,

    which versions do you mean by
    recent versions of PUN
    ? According to the changelog this have been fixed in PUN 1.78. I tested this behaviour a few moments ago and it worked as intended. If you have this issue in PUN 1.78 and/or above please let us know.
  • ahoogol
    ahoogol
    edited November 2016
    Options
    @Christian_Simon , hi
    i means 1.78 and even 1.79. both are tested by me.
    ahoogol said:


    If i commend LATE JOINING feature (NetworkingPeer.cs line 4108), all will be OK.

    sorry, i means commenting.
  • jeanfabre
    Options
    Hi,

    Are you calling PhotonNetwork.SetMasterClient() manually or are you simply closing down actor 1?

    Bye,

    Jean
  • jeanfabre
    Options
    Hi,

    one more thing, do you have PlayerTtl value greater than 0?

    Bye,

    Jean
  • ahoogol
    Options
    Hi @jeanfabre, thanks for your reply
    jeanfabre said:


    Are you calling PhotonNetwork.SetMasterClient() manually or are you simply closing down actor 1?

    Yes, i call manually
    jeanfabre said:


    do you have PlayerTtl value greater than 0?

    Yes
  • jeanfabre
    Options
    Hi,

    Ok. Yes it's a tricky situation here :)

    can you try to add this in the PhotonView class?

    public int currentMasterID = -1; public void OnMasterClientSwitched(PhotonPlayer newMasterClient) { if (CreatorActorNr == 0 && !OwnerShipWasTransfered && (currentMasterID== -1 || ownerId==currentMasterID)) { ownerId = newMasterClient.ID; } currentMasterID = newMasterClient.ID; }
    And let me know if it works. So far my tests are showing the proper behaviour and fixes manually assignment of Masterclients.

    If this works, I'll submit this to the team for review.

    Bye,

    Jean
  • ahoogol
    ahoogol
    edited November 2016
    Options
    Hi @jeanfabre,
    I added your code, and tested it. when master client is switched, your code correctly change ownerId to new master. but in some photon views, immediately after that, ownerId returned to previous master client in the LATE JOINING feature code (NetworkingPeer.cs line 4108).
    These exceptional photon views has different config than others:
    1. has been instantiated dynamically by calling PhotonNetwork.InstantiateSceneObject()
    2. their observe option is Unreliable instead of Unreliable On Change in others
  • jeanfabre
    Options
    Hi,

    Ok, I'll investigate and let you know about the findings and if we have a possible fix.

    Bye,

    Jean
  • jeanfabre
    Options
    Hi,

    I could not repro this, neither with InstantiateSceneObject not Unreliable on Change

    do you have steps to repro? I'll try to follow them,.

    Bye,

    Jean
  • ahoogol
    ahoogol
    edited November 2016
    Options
    Hi @jeanfabre,
    These steps repro it:
    1. actor1 connects to photon with authentication and creates room with these options:
    public void CreateMatch()
        {
            var roomOptions = new RoomOptions()
            {
                IsOpen = true,
                IsVisible = true,
                PublishUserId = true,
                PlayerTtl = 60* 1000,
                EmptyRoomTtl = 0,
                MaxPlayers = 10,
                CustomRoomProperties = new Hashtable()
                {
                    ...
                },
                CustomRoomPropertiesForLobby = new[]
                {
                    ...
                }
            };
            var sqlLobby = new TypedLobby(_lobbyName, LobbyType.SqlLobby);
            PhotonNetwork.CreateRoom(null, roomOptions, sqlLobby);
        }
    2. actor2 connect to photon with authentication and joins the room actor1 created with JoinRandomRoom.
    3. actor1 (current masterClient) instantiate a scene object from a prefab in which the photonView observe option is Unreliable (not on Change):
    public Transform TargetPrefab;
    public void InstantiateSceneOwned()
        {
            var go = PhotonNetwork.InstantiateSceneObject(TargetPrefab.name, Vector3.zero, Quaternion.identity, 0, null);
            go.name += "-Scene";
        }
    4. actor2 calls PhotonNetwork.SetMasterClient(PhotonNetwork.player); and so become new masterClient.

    I inspected the photonView in both actors in the folowing format: [photonView.CreatorActorNr, photonView.ownerId, photonView.isMine]:
    after step 3: actor1:[0,0,True] actor2:[0,1,False]
    after step 4: actor1:[0,2,False] actor2:[0,1,False]
    after step4 in actor2 Console Log:
    
    OwnerId changed to 2 (PhotonView.cs:686 - OnMasterClientSwitched you requested me to add!!!)
    Adjusting owner to sender of updates. From: 2 to: 1 (NetworkingPeer.cs:4111)
    Note:
    1. I tested it on two player instance: one on a android device and other on unity editor
    2. I used custom authentication and owned server for OnPremise Photon server
    3. its rarely that actor2 works correctly ([0,2,True]). so you should retest to see bug.
  • jeanfabre
    Options
    hi,

    indeed, there is a lot more this. Ok, I'll go over this and try to find out what's going on. thanks for the clear explanations, it helps a lot.

    Bye,

    Jean
  • jeanfabre
    Options
    Hi,

    woah, I am trying hard and I can't repro still... I have the exact same procedure as you describe and it all works fine.Tested several time and made sure it was following the exact same procedure and setup for room, lobby, photonView. But I do not go with authentification and custom on promise server, could that be it? I doubt it very much though.

    Can you confirm that this bug happens if you connect to our cloud and with no authentication?

    Bye,

    Jean
  • ahoogol
    ahoogol
    edited November 2016
    Options
    Hi @jeanfabre,
    Yes, i tested it on your cloud with no authentication, and its behavior is same. :(
    PUN Version 1.79
  • ahoogol
    Options
    Finally, i fixed the bug by adding the condition && view.currentMasterID == -1 to NetworkingPeer.cs:4108. :)
    if (sender.ID != view.ownerId && (!view.OwnerShipWasTransfered || view.ownerId == 0) && view.currentMasterID == -1)
            {
                // obviously the owner changed and we didn't yet notice.
                Debug.Log("Adjusting owner to sender of updates. From: " + view.ownerId + " to: " + sender.ID);
                view.ownerId = sender.ID;
            }
    I prevented from touching ownerId of view after that master client is switched a moment ago. is this correct or it may has better solution?
  • jeanfabre
    Options
    Hi,

    What's really an issue is that I can't repro this. I'll keep trying.

    I am not sure I understand your statement on touching the ownerId, can you rephrase? thanks :)

    Bye,

    Jean
  • ahoogol
    Options
    Hi @jeanfabre,
    sorry for my bad English. it is not my natural language. :)
    I prevented from touching ownerId of view after that master client is switched a moment ago.

    i means, i prevented from changing ownerId in that line with adding that condition.
    I surprised that you can not repro this issue. :open_mouth:
    So i sent a simple scene with a few code to repro the issue. please try to import this package: https://ufile.io/2d527

    Try to run two instances of it: one unity player and one windows exe for example. then click on connect button and wait to display [0,1,True] on screen. then in the other instance, click on connect and wait to display [0,1,False]. Oops, in first instance, screen now display [0,2,False]!!! two instances display False for isMine of scene photonView.