Incorrect IF Decision in C# - Zed Graph Out of Range Error - RollingPointPairList

139 views Asked by At

This is really mind-boggling. I am using RollingPointPairList of Zed Graph, and I kept getting an error saying Argument Out of Range. So I decided to use the source code of Zed Graph instead of .dll files. I can now see where the exception is thrown. But I am totally perplexed to see why.

This is where the exception is thrown:

Original code from RollingPointPairList:

public PointPair this[int index]
    {
        get
        {
            if (index >= Count || index < 0)
            {
                    throw new ArgumentOutOfRangeException();
            }
            index += _tailIdx;
            if ( index >= _mBuffer.Length )
                index -= _mBuffer.Length;

            return _mBuffer[index];
        }

Surprisingly, index was never greater or equal to count, or less than 0.

I modified the code to see what was really going on like this:

if (index >= Count || index < 0)
            {
                Console.WriteLine(index + " " + Count);
                Console.Beep(5000, 1000);
                if (index >= Count || index < 0)
                {
                    throw new ArgumentOutOfRangeException();
                }
            }

So I did hear the beep, and it did output something, but this time did not reach the throw excpetion, because of the second if check.

Here is what I see on the output:

Output

Any idea what could be causing this issue?

P.S. I have made sure that multiple threads do not try to modify RollingPointPairList

0

There are 0 answers