Unity editor freeze after room creation call

Unity: 2019.4.18f1 (Last LTS)
Photon: PUN 2 (2.27)

Aim: multiplayer game with several clients (5-15) in same room, but different scenes/worlds.
Starting scene is just UI window with button. Enter User ID and room name and press connect.
Usually then locally the correct scene would load (locally, no automatic synchronization; because of same room, different scenes, necessary for cross-room/inter-scene communication)
and you could walk around. To some extent also different player's objects were visible and synchronized.

Since 3 days now, after calling JoinOrCreateRoom() or CreateRoom() the Unity editor will freeze/become entirely unresponsive, so that you gotta shoot it with task manager.
Callback of the Method is always "true", so success.
However no further method is called. In taks manager you can see, that the editor is eating more and more memory.
I have Debug.Log calls in OnRoomCreated, ...Joined, ...JoinFailed, however none of these are called.

I have not worked on the connection code recently, since it was working, but rather on in scene instantiation and parenting of objects.
And now I'm quite out of ideas.

I am quite new to Unity and so I don't really know if it's a Unity or a PUN problem.

Best regards,
fc

Comments

  • Well ok, the error was not the room creation call.
    After some (a lot) trial and error I can say, that the reason why the program is going into infinite loop is the way i have handled the PhotonViewCollection calls.

    The way I tried to cycle through all other available PhotonViews in the Scene was:
    while ( PhotonNetwork.PhotonViewCollection.MoveNext() )
    

    The documentation tells, that it would stop after the last entry, however this does not appear to be the case.

    I am still searching for a solution on how to cycle all current PhotonViews in the scene.
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @fluffyCucumber,

    Thank you for choosing Photon and for your report!

    I have managed to reproduce.
    We will fix this.
  • emotitron
    emotitron ✭✭✭
    You just need to use foreach( ), of if you want to loop yourself cache the iterator rather than getting a new one every loop.

    Tobi tested this and it works correctly:
    var iterator = PhotonNetwork.PhotonViewCollection;
    while (iterator.MoveNext())
    {
    }
    
  • We are still discussing which changes to make but the problem is this:

    The PhotonViewCollection uses photonViewList.Values, which creates a new iterator every time it's called.
    This is by design, so you could iterate over the (current) Values.
    If you go with
    foreach (PhotonView view in PhotonNetwork.PhotonViewCollection)
    
    , there is no problem.
    If you'd use your approach on a dictionary, it would look like this (more or less):
    while (dict.Values.GetEnumerator().MoveNext())
    
    and it would also fail in the same way.

    It's unfortunate that this is an infinite loop.
    At the moment, we think maybe we just change the naming of PhotonViewCollection.

    Sorry for the hassle.
    Thanks for reporting this and not giving up on Photon instead!
  • foreach does the trick

    Thanks a lot.