What Does This Error Mean?

Hi,
I'm using OnPhotonSerializeView to send and receive information between players. It works most of the time however I will occasionally get the following error:
IndexOutOfRangeException: Array index is out of range.
PhotonStream.ReceiveNext () (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonClasses.cs:1069)
Stream.OnPhotonSerializeView (.PhotonStream stream, PhotonMessageInfo info) (at Assets/Scripts/Pixel World/Stream.cs:32)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
PhotonView.ExecuteComponentOnSerialize (UnityEngine.Component component, .PhotonStream stream, PhotonMessageInfo info) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:553)
PhotonView.DeserializeComponent (UnityEngine.Component component, .PhotonStream stream, PhotonMessageInfo info) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:378)
PhotonView.DeserializeView (.PhotonStream stream, PhotonMessageInfo info) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:363)
NetworkingPeer.OnSerializeRead (System.Object[] data, .PhotonPlayer sender, Int32 networkTime, Int16 correctPrefix) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:4361)
NetworkingPeer.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2612)
ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (System.Byte[] inBuff)
ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands ()
ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands ()
PhotonHandler.Update () (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:153)


What does this mean and how might I go about solving it?

Thanks in advance.

Best Answer

Answers

  • Hi @YBtheS,

    it looks like you are trying to read too much data (more than there actually is). Please check what data you are sending and make sure, that you don't try to read more than that data. Each call of SendNext(object obj) on the sending side can be covered by one call of ReceiveNext() on the receiving side.
  • Hi @YBtheS,

    it looks like you are trying to read too much data (more than there actually is). Please check what data you are sending and make sure, that you don't try to read more than that data. Each call of SendNext(object obj) on the sending side can be covered by one call of ReceiveNext() on the receiving side.

    Okay. Thanks for the response. Is that not what I'm doing here though?

    using System.Collections; using System.Collections.Generic; using UnityEngine; public class Stream : MonoBehaviour { private Color32 color; void Update() { color = this.GetComponent<SpriteRenderer>().color; } //Stream settings void Start() { //These are all default values for now PhotonNetwork.sendRate = 20; PhotonNetwork.sendRateOnSerialize = 20; } //Converts primitive long to a non-primitive Color Color longToColor(long num) { return new Color(num / 1000000000, num / 1000000 % 1000, num / 1000 % 1000, num % 1000); } //Used to send and recieve data over the network void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if(stream.isWriting) { stream.SendNext(long.Parse("" + color.r + color.b + color.g + color.a)); } else { this.GetComponent<SpriteRenderer>().color = longToColor((long)stream.ReceiveNext()); Debug.Log("Recieved: " + longToColor((long)stream.ReceiveNext())); } } }
  • You are calling stream.ReceiveNext(); twice. First when applying the received value to the SpriteRenderer and second when logging something to the console. You can just do this once because you only send one value.

    Thanks! That worked
  • um hey, i know this old one, but recently i have the same errors. and i dont have duplicate line. idk why, it actually works very fine...until idk why the spamming error keeps coming out.