Fixed null exceptions in memorysegment that appeared in my rtp client

Topics: Bug
Dec 12, 2016 at 8:43 AM
Edited Dec 12, 2016 at 4:00 PM
Hello Julius,

thanks a lot again for your library :-)

in memorysegment.cs I made theses changes in the latest 112204:

Yours:
    [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public bool Equals(MemorySegment other)
    {

        return other.GetHashCode().Equals(GetHashCode());

    }

Mine
    [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public bool Equals(MemorySegment other)
    {
        if (other != null)
            return other.GetHashCode().Equals(GetHashCode());
        else return false;
    }


Yours
    [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static bool operator !=(MemorySegment a, MemorySegment b) { return a.Equals(b).Equals(false); }

Mine
    [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
    public static bool operator !=(MemorySegment a, MemorySegment b) {
        if (!object.ReferenceEquals(a, null) && !object.ReferenceEquals(b, null))
            return a.Equals(b).Equals(false);
        else
            return (!object.ReferenceEquals(a, null) || !object.ReferenceEquals(b, null));
    }

This way I do no "object not set to an instance"... exceptions anymore, I had theses before in depacketizing. This way it works for me with the latest Version now!


One Thing I sometimes have is an exception here when ending the Client:

In RTPClient.Methods line 1445:

do received += justRecieved = socket.ReceiveFrom(buffer.Array, buffer.Offset + received, buffer.Count - received, System.Net.Sockets.SocketFlags.None, ref remote);

I am just examining that. It is a bit bad, because it only happens in some cases when stopping the Client, but after that I do not get a Video anymore in the next call (around 5 times it works before starting and stopping without Problems)...

Would you consider making an update with my changes? Are These okay?

Thanks a lot!