NullReference on stream.ReceiveNext after upgrading Unity from 2017.4 to 2018.3

Options
So the game is already a big project. We're right now working on ports (that's why we had to upgrade unity).
What happens is that roughly 50% of times when a player enters a room, we get a nullreference on OnPhotonSerialize {stream.ReceiveNext()}

What appears to me is that the client is trying to read more than what was written on the Photon serialization stream.

Do you have any leads on how to debug it? I'm not even sure if the root cause is on our side or Photon's.
I suppose there would be a place in the codebase where a client would write few bytes and other place where a client would read more bytes.

A few questions:
- If one OnPhotonSerialize reads too much data, does it affect the next OnPhotonSerialize (on the next behaviour) or Photon know how much data that behaviour should read?
- After a round of OnPhotonSerialize() (where photon calls every OnPhotonSerialize of every behaviour), is there a way to know if there are any bytes left? i.e. no behaviour read them.

We need a way to track this bug down on a large codebase

Thanks

Best Answer

  • BitCakeStudio
    Answer ✓
    Options
    We think we found the issue. If we're correct, it was our fault as we had a branch inside OnPhotonSerialize which caused more reads than writes to the serialization stream. We fixed it by always sending a boolean first to indicate if there's data to be read.

    Should we continue to face this issue, I'll post again here. Thanks for the help, tho!

Answers

  • BitCakeStudio
    edited June 2019
    Options
    oh, forgot to add:
    - we're using PUN v1.94 (13. February 2019)
    - we tried using the latest version but it breaks on WebGL (important)

    Exception: Deserialize(): 7 pos: 6 bytes: 55. F3-07-01-FF-FF-07-2F-4D-69-73-73-69-6E-67-20-76-61-6C-75-65-20-31-20-28-50-69-6E-67-52-65-71-75-65-73-74-2E-43-6C-69-65-6E-74-54-69-6D-65-53-74-61-6D-70-29-0D-0A-00
    ExitGames.Client.Photon.Protocol16.Deserialize (ExitGames.Client.Photon.StreamBuffer din, Byte type)
    ExitGames.Client.Photon.Protocol16.DeserializeOperationResponse (ExitGames.Client.Photon.StreamBuffer stream)
    ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (ExitGames.Client.Photon.StreamBuffer stream)
    ExitGames.Client.Photon.TPeer.DispatchIncomingCommands ()
    ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands ()
    PhotonHandler.Update () (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:161)

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @BitCakeStudio,

    Thank you for choosing Photon!

    Send us an email to developer@photonengine.com with a link to this forum discussion and all details.
  • GreenEclipse
    edited June 2019
    Options
    Bump :) I am having a similar issue :/ Would be nice to have some hints on how to solve this @JohnTube
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited June 2019
    Options
    Hi @GreenEclipse,

    Thank you for choosing Photon!

    We also received an email, maybe from you.

    @BitCakeStudio @GreenEclipse

    First, update to latest PUN Classic 1.97 and try again.

    We will look into this.
    We are very busy this week so bear with us :)

    Could you, in the meantime, verify that this is related to the Unity version?
    Maybe it's related to the scripting backend chosen (IL2CPP or mono) or mono version?
    Could you try different Unity versions and different player/build settings?
    Also, make sure this happens on WebGL only, Editor only or builds also?
  • GreenEclipse
    edited June 2019
    Options
    Hey @JohnTube

    Thanks for the fast response :) I'm using the latest version since i created a clean project a few days ago. Unity version is 2018.3.0f2 . So there aren't any other scripts that could be an issue at least not the ones i've created. I'm kinda busy but can try later on different versions of unity. I've tried different build settings the 2 i've tried is : PC and WebGL and the error is only on WebGL. I can confirm also that it is in editor and build also.

    Oh and i've also send an email to the support you mentioned to bitcakestudio. Hope it's not an issue.
    As for the time i haveno problem waiting as long as i get a notification with a solution when it gets fixed. Hope that's not asking too much :)
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    In latest PUN 1.97, in file "Assets\Photon Unity Networking\Plugins\PhotonNetwork\NetworkingPeer.cs", inside NetworkingPeer.SetupProtocol

    replace line 800:
    
            #endif
    with:
            SocketWebTcp.SerializationProtocol = Enum.GetName(typeof(SerializationProtocol), this.SerializationProtocolType);
            #endif
    So the block is now:
            #if UNITY_WEBGL
            if (this.TransportProtocol != ConnectionProtocol.WebSocket && this.TransportProtocol != ConnectionProtocol.WebSocketSecure)
            {
                Debug.Log("WebGL only supports WebSocket protocol. Overriding PhotonServerSettings.");
                protocolOverride = ConnectionProtocol.WebSocketSecure;
            }
            PhotonHandler.PingImplementation = typeof(PingHttp);
            SocketWebTcp.SerializationProtocol = Enum.GetName(typeof(SerializationProtocol), this.SerializationProtocolType);
            #endif
    Sorry for the inconvenience.
    Could you report back if this fix is working as expected?
  • GreenEclipse
    Options
    Just got the same response from the support and that fixed my issue! Thanks for the help and posting the solution for the next user that encounters this issue :)
  • BitCakeStudio
    Answer ✓
    Options
    We think we found the issue. If we're correct, it was our fault as we had a branch inside OnPhotonSerialize which caused more reads than writes to the serialization stream. We fixed it by always sending a boolean first to indicate if there's data to be read.

    Should we continue to face this issue, I'll post again here. Thanks for the help, tho!