OnPhotonSerializeView error IndexOutOfRangeException

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

OnPhotonSerializeView error IndexOutOfRangeException

qilS
2021-01-20 19:38:04

Hi,
I'm using >OnPhotonSerializeView

to send and receive the health of the enemy in the photon. it works most of the time, but suddenly I got countless errors. The error as shown below,

IndexOutOfRangeException: Index was outside the bounds of the array.
Photon.Pun.PhotonStream.ReceiveNext () (at Assets/Photon/PhotonUnityNetworking/Code/PunClasses.cs:694)
Photon.Pun.PhotonTransformView.OnPhotonSerializeView (Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/Views/PhotonTransformView.cs:127)
Photon.Pun.PhotonView.DeserializeComponent (UnityEngine.Component component, Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs:351)
Photon.Pun.PhotonView.DeserializeView (Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs:341)
Photon.Pun.PhotonNetwork.OnSerializeRead (System.Object[] data, Photon.Realtime.Player sender, System.Int32 networkTime, System.Int16 correctPrefix) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:1732)
Photon.Pun.PhotonNetwork.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:2102)
Photon.Realtime.LoadBalancingClient.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:3018)
ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (ExitGames.Client.Photon.StreamBuffer stream) (at <11e9abbca912444aa80ed58a280369fc>:0)
ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands () (at <11e9abbca912444aa80ed58a280369fc>:0)
ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands () (at <11e9abbca912444aa80ed58a280369fc>:0)
Photon.Pun.PhotonHandler.Dispatch () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:205)
Photon.Pun.PhotonHandler.FixedUpdate () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:139)

anyone ever encounter this? i have read the person before but i only have a single line of receivenext.

//sync health  
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)  
    {  
        if (stream.IsWriting)  
        {  
            // We own this player: send the others our data  
            stream.SendNext(health);  
        }  
        else  
        {  
            // Network player, receive data  
            health = (float)stream.ReceiveNext();  
        }  
    }

Comments

Tobias
2021-01-21 10:12:04

This is odd. Which version of PUN 2 is it?
How can we reproduce this? Does it happen in some specific situation or ...?

Tobias
2021-01-21 10:12:50

Did you run the debugger when this happens? What is the content/value of the stream?
Is some other component also reading the incoming stream? Then, maybe that was reading too many entries already?

qilS
2021-03-08 04:00:18

@Tobias wrote: »

This is odd. Which version of PUN 2 is it?
How can we reproduce this? Does it happen in some specific situation or ...?

sorry i just came back today. it is PUN 2.

@Tobias wrote: »

Did you run the debugger when this happens? What is the content/value of the stream?
Is some other component also reading the incoming stream? Then, maybe that was reading too many entries already?

i guess maybe this is it. but does it mean on another photon player, I shouldn't put the lines?

qilS
2021-03-08 04:00:42

Thank you Tobias for the reply,

Back to top