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.
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.
1
Best Answer
-
Hi,
me neither, so don't worry, we are pretty much all ont he same boat with english... )
thanks for the example. I can repro now, and yes you have the right solution. I'll check with the engineers to validate this, and if it passes, it will be in the next update.
thanks for your patience, it helped a lot
Bye,
Jean5
Answers
-
Hi ahoogol,
which versions do you mean byrecent 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.0 -
@Christian_Simon , hi
i means 1.78 and even 1.79. both are tested by me.
sorry, i means commenting.ahoogol said:
If i commend LATE JOINING feature (NetworkingPeer.cs line 4108), all will be OK.
0 -
Hi,
Are you calling PhotonNetwork.SetMasterClient() manually or are you simply closing down actor 1?
Bye,
Jean0 -
Hi,
one more thing, do you have PlayerTtl value greater than 0?
Bye,
Jean0 -
Hi @jeanfabre, thanks for your reply
Yes, i call manuallyjeanfabre said:
Are you calling PhotonNetwork.SetMasterClient() manually or are you simply closing down actor 1?
Yesjeanfabre said:
do you have PlayerTtl value greater than 0?
0 -
Hi,
Ok. Yes it's a tricky situation here
can you try to add this in the PhotonView class?
And let me know if it works. So far my tests are showing the proper behaviour and fixes manually assignment of Masterclients.
public int currentMasterID = -1; public void OnMasterClientSwitched(PhotonPlayer newMasterClient) { if (CreatorActorNr == 0 && !OwnerShipWasTransfered && (currentMasterID== -1 || ownerId==currentMasterID)) { ownerId = newMasterClient.ID; } currentMasterID = newMasterClient.ID; }
If this works, I'll submit this to the team for review.
Bye,
Jean
0 -
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 others0 -
Hi,
Ok, I'll investigate and let you know about the findings and if we have a possible fix.
Bye,
Jean0 -
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,
Jean0 -
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 callsPhotonNetwork.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.0 -
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,
Jean0 -
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,
Jean0 -
Hi @jeanfabre,
Yes, i tested it on your cloud with no authentication, and its behavior is same.
PUN Version 1.790 -
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?0 -
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
0 -
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.
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.0 -
Hi,
me neither, so don't worry, we are pretty much all ont he same boat with english... )
thanks for the example. I can repro now, and yes you have the right solution. I'll check with the engineers to validate this, and if it passes, it will be in the next update.
thanks for your patience, it helped a lot
Bye,
Jean5