Placeholder-Software / Dissonance

Unity Voice Chat Asset
71 stars 5 forks source link

NullReferenceException in HlapiClient:95 when client starts #50

Closed TobiasWehrum closed 7 years ago

TobiasWehrum commented 7 years ago

Context

A NullReferenceException gets thrown exactly once on a client when we start our app - maybe before the client is connected. It originates from HlapiClient.cs:95 because "connection" is null.

private bool Send(ArraySegment<byte> packet, byte channel)
        {
            if (_network.PreprocessPacketToServer(packet))
                return true;

            var length = _network.CopyPacketToNetworkWriter(packet, _sendWriter);

            // the next line is line 95
            if (!NetworkManager.singleton.client.connection.SendBytes(_sendWriter.AsArray(), length, channel))
            {
                return false;
            }

            return true;
        }

Expected Behavior

No exceptions or errors thrown on startup.

Actual Behavior

A NullReferenceException when the client tries to use connection before it is available (probably before it is connected?).

Your Environment

martindevans commented 7 years ago

Hi Tobias,

I suspect this is a duplicate of the same fundamental issue in #48. Could you try the workaround I mention here?

TobiasWehrum commented 7 years ago

Hi Martin, works! Will this be in the next version of Dissonance?

martindevans commented 7 years ago

Yep, assuming Gabe doesn't have any problems with it and it passes code review it should be in the next version of Dissonance :)

TobiasWehrum commented 7 years ago

Fingers crossed for that. Thanks!

martindevans commented 7 years ago

Hi Tobias,

Since this is a duplicate of #48 I'll close it now. If you want to get alerts about comments in that thread click the "subscribe" button on the right of the issue.