IndexOutOfRangeException: Array index is out of range.

Options
Hello all,
I overrided the LeaveRoom function of vikingdemo in PUN to test my server, but when i click LeaveRoom button in the game ,a error show up as the title.
Here is my code:
//the code in GameManagerVik.cs
       var playerStatus_table=new Dictionary<byte,object>{{(byte)ParameterCode.PlayerProperties,playerStatus}};
	PhotonNetwork.LeaveRoom(playerStatus_table);
     //   PhotonNetwork.LeaveRoom();

//***  this function is in PhotonNetwork.cs,just add a parameter
public static bool LeaveRoom(Dictionary<byte,object> playerStatus)  

//***  this function is in NetworkPeer.cs,just add a parameter and send to OpCustom
public virtual bool OpLeave(Dictionary<byte,object> playerStatus)
	{
		if (this.State != global::PeerState.Joined)
		{
			Debug.LogWarning("Not sending leave operation. State is not 'Joined': " + this.State);
			return false;
		}
		
		return this.OpCustom((byte)OperationCode.Leave, playerStatus, true, 0);
	}

the details of error:
IndexOutOfRangeException: Array index is out of range.
ExitGames.Client.Photon.Protocol.SerializeDictionaryHeader (System.IO.MemoryStream writer, System.Object dict, System.Boolean& setKeyType, System.Boolean& setValueType)
ExitGames.Client.Photon.Protocol.SerializeDictionary (System.IO.MemoryStream dout, IDictionary serObject, Boolean setType)
ExitGames.Client.Photon.Protocol.Serialize (System.IO.MemoryStream dout, System.Object serObject, Boolean setType)
ExitGames.Client.Photon.Protocol.SerializeParameterTable (System.IO.MemoryStream memStream, System.Collections.Generic.Dictionary`2 parameters)
ExitGames.Client.Photon.Protocol.SerializeOperationRequest (System.IO.MemoryStream memStream, Byte operationCode, System.Collections.Generic.Dictionary`2 parameters, Boolean setType)
ExitGames.Client.Photon.EnetPeer.SerializeOperationToMessage (Byte opc, System.Collections.Generic.Dictionary`2 parameters, EgMessageType messageType, Boolean encrypt)
ExitGames.Client.Photon.EnetPeer.EnqueueOperation (System.Collections.Generic.Dictionary`2 parameters, Byte opCode, Boolean sendReliable, Byte channelId, Boolean encrypt, EgMessageType messageType)
ExitGames.Client.Photon.PeerBase.EnqueueOperation (System.Collections.Generic.Dictionary`2 parameters, Byte opCode, Boolean sendReliable, Byte channelId, Boolean encrypted)
ExitGames.Client.Photon.PhotonPeer.OpCustom (Byte customOpCode, System.Collections.Generic.Dictionary`2 customOpParameters, Boolean sendReliable, Byte channelId)
NetworkingPeer.OpLeave (System.Collections.Generic.Dictionary`2 playerStatus) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:988)
PhotonNetwork.LeaveRoom (System.Collections.Generic.Dictionary`2 playerStatus) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:1828)
GameManagerVik.OnGUI () (at Assets/DemoVikings/Scripts/GameManagerVik.cs:67)

At the beginning,i thought the data is overflow,but i just store a string in dictionary still have the same problem.
I dont have any idea to fix this. :(
Please help me ,thxs. :)

Comments

  • Tobias
    Options
    I can't check this at the moment but will try this week.
    I think it's a bug that's fixed in PUN 1.50.3 (the main asset in the Asset Store). The Viking Demo is a bit older and maybe has a bug with serialization (which you see).
    Please try this in the latest PUN package, too.

    In general, OpLeave is not really built to include state or anything custom. I don't think your dictionary will arrive at the other clients.
  • Thank you for your quick reply ,Tobias.You are right,the dictionary can't even arrive my sever.
    So,as you said "In general, OpLeave is not really built to include state or anything custom."
    How can I handle leave Operation to save the state of player,use a OpCustom by self or something other?
  • Tobias
    Options
    In Turnbased, we do the following: Anything that's relevant for state has to be a buffered event or a Custom Property. Those things are in the server anyways and when everyone left, we store this as state. When this game gets re-joined (by name, by a player who was in that game before), then we can either find the game in memory or load it.

    If you put the state in OpLeave you will loose it when a client crashed or loses connection suddenly without calling OpLeave.
  • Thank you Tobias,I will do what you said.BTW,I downloaded the last PUN and fixed the problem.
  • Tobias
    Options
    Super. Thanks for letting us know!