LoadBalancing.Room..ctor throws NullReferenceException
Hi~ I reviewed ParticleDemo project using Photon realtime sdk on Unity 5.3.5f1.
First of all, one of clients created a room by CreateParticleDemoRoom function and another client tried to join that room by OpJoinRandomRoom function.
one client use this code,
So, I called
But, When the second client found a room and tried to join, I got a
Please let me know what is a problem.
First of all, one of clients created a room by CreateParticleDemoRoom function and another client tried to join that room by OpJoinRandomRoom function.
one client use this code,
case ClientState.ConnectedToMaster: // when that's done, this demo asks the Master for any game. the result is handled below // this.OpJoinRandomRoom(null, 0); this.CreateParticleDemoRoom(DemoConstants.MapType.Forest, 16); break;another client like this :
case ClientState.ConnectedToMaster: // when that's done, this demo asks the Master for any game. the result is handled below this.OpJoinRandomRoom(null, 0); //this.CreateParticleDemoRoom(DemoConstants.MapType.Forest, 16); break;My Intention is the first client make a room, and second client joined the room not using specific room name.
So, I called
OpJoinRandomRoom()
function on the second client.But, When the second client found a room and tried to join, I got a
NullReferenceException
below.
NullReferenceException: Object reference not set to an instance of an object ExitGames.Client.Photon.LoadBalancing.Room..ctor (System.String roomName, ExitGames.Client.Photon.LoadBalancing.RoomOptions options) ExitGames.Client.DemoParticle.ParticleRoom..ctor (System.String roomName, ExitGames.Client.Photon.LoadBalancing.RoomOptions opt) ExitGames.Client.DemoParticle.GameLogic.CreateRoom (System.String roomName, ExitGames.Client.Photon.LoadBalancing.RoomOptions opt) (at Assets/Photon/DemoCode/GameLogic.cs:242) ExitGames.Client.Photon.LoadBalancing.LoadBalancingClient.GameEnteredOnGameServer (ExitGames.Client.Photon.OperationResponse operationResponse) (at Assets/PhotonLoadbalancingApi/LoadBalancingClient.cs:1707) ExitGames.Client.Photon.LoadBalancing.LoadBalancingClient.OnOperationResponse (ExitGames.Client.Photon.OperationResponse operationResponse) (at Assets/PhotonLoadbalancingApi/LoadBalancingClient.cs:1959) ExitGames.Client.DemoParticle.GameLogic.OnOperationResponse (ExitGames.Client.Photon.OperationResponse operationResponse) (at Assets/Photon/DemoCode/GameLogic.cs:424) ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (System.Byte[] inBuff) ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands () ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands () ExitGames.Client.DemoParticle.GameLogic.UpdateLoop () (at Assets/Photon/DemoCode/GameLogic.cs:252) Logic.UpdateLocal () (at Assets/Scripts/Logic.cs:124) DemoGUI.Update () (at Assets/Scripts/DemoGUI.cs:109)I ran demo project from Photon sdk , I just changed one line for joining random room.
Please let me know what is a problem.
0
Answers
What you are doing is quite complex, if you think about it: You build one version to join and one to create rooms? How does a player know which one to start??
The workflow in the demo is to attempt to join the room "Demo". CreateParticleDemoRoom uses OpJoinOrCreateRoom to achieve this.
The best workflow is to attempt to join a random room and to only create one when random join fails.
See: https://doc.photonengine.com/en-us/realtime/current/reference/matchmaking-and-lobby
The place where you changed code is not the place you should change.
Do this:
In GameLogic.OnStateChanged(), case ClientState.ConnectedToMaster, call JoinRandomRoom.
In OnOperationResponse, the result of JoinRandomRoom is handled. Instead of calling CreateParticleDemoRoom, you can do your OpCreateRoom call.
Hope that helps.
The reason why I built one version to join and one to create rooms is for test.
I think it gave you some confusion.
As you mentioned,
OpJoinRandomRoom is called in GameLogic.OnStateChanged(), case ClientState.ConnectedToMaster,
I did at the first. If player can't find match, call OpCreateRoom in OnOperationResponse.
(I use your demo project itself) If there is no room, successfully created room.
If there is a ROOM, finally Photon found match, called GameEnteredOnGameServer function internally
and then throw exception at
this.CurrentRoom = this.CreateRoom(this.enterRoomParamsCache.RoomName, this.enterRoomParamsCache.RoomOptions);
I used your demo, so i didn't change many thing.
in your demo, OpJoinOrCreateRoom is only used for join and create room.
I just called JoinRandomRoom in GameLogic.OnStateChanged(), case ClientState.ConnectedToMaster.
to use your join random function. when join random room fails, call OpCreateRoom.
I just replaced OpJoinOrCreate with OpJoinRandomRoom.
Because I wanted to use your random join function. That's it. This was all I did.
So, I don't think that I did try complex thing.
if there are some part I didn't understand, please let me know.
Thank you in advance.
I looked at another demo which works well with OpJoinRandomRoom.
This project doesn't use extended room class.
So, I tried not to use ParticleRoom class which is extended room class(derived class of Room)
now, OpJoinRandomRoom worked well.
it is better not to derived room class.
even derived room class, ParticleRoom.cs in this project, doesn't have any methods, the problem is always happened.
So, I decide not to extend room class.
please check this point.
Thank you for your helping.
GameLogic.cs in your demo project.
you override CreateRoom function like below. and this is base function in LoadBalancingClient.cs So, If we want to inherit LoadBalancing class and Room class for our own logic,
We have to do like this.
Thank you for your detailed reports. We will take a look at this.
I hope there is nothing blocking you meanwhile.