Valhalla Legends Forums Archive | General Programming | MBNCSUtil.BncsReader problem

AuthorMessageTime
DarkDarkDark
Hello I'm trying to use the MBNCSUtil.BncsReader with my data buffer but I'm stuck after messing around with it.

[code]
Dim format As MBNCSUtil.BncsReader = New MBNCSUtil.BncsReader(buffer)
[/code]

However I get a "Arithmetic operation resulted in an overflow". The data buffer only contains the ping pocket. (8 bytes long: 225, 37, 8, 0, 41, 47, 146, 76)

It also happens with the SIDAUTHCHECK pocket, which is 9 or 8 bytes long.


Thanks for any help.
February 27, 2010, 9:48 PM
Myndfyr
I'm not able to reproduce this error.  What version of mbncsutil.dll are you using?

[code]
        static void Main(string[] args)
        {
            byte[] sampleBuffer = new byte[] { 255, 37, 8, 0, 41, 47, 146, 76 };
            BncsReader reader = new BncsReader(sampleBuffer);
            int ping = reader.ReadInt32();
        }
[/code]
February 27, 2010, 10:28 PM
DarkDarkDark
hmmm the MBNCSUtil-2.1.7.22-fre.zip on your google site.

I just re-downloaded and re-referenced it but that didn't work. Another example: (255,37,8,0,88,19,21,14)

all I'm doing it rediming my buffer, getting the data and making the bncsreader:

[code]
databuffer(7) 'function
client.BeginReceive(buffer, 0, 8, SocketFlags.None, AddressOf ReceiveCallback, buffer)
Dim format1 As MBNCSUtil.BncsReader = New MBNCSUtil.BncsReader(buffer)
[/code]

I also tried what you did and it worked, however with my main example (above) when I set a break point on it, it'll work. When I set a break point in a different sub it doesn't work.
February 28, 2010, 2:09 AM
Myndfyr
I don't know what "databuffer(7)" means (since it's not referenced anywhere), and then you call BeginReceive which is a non-blocking call, then instantiate BncsReader with what is probably an empty receive buffer.

Do you mind posting more complete code?  It's not like anyone's going to steal it....
February 28, 2010, 4:26 AM
Myndfyr
Yes, I am correct.  Here is sample code.  I used VB to verify it wasn't just a VB issue:
[code]
   Sub Main()
       Dim sampleBuffer(7) As Byte
       sampleBuffer(0) = 255
       sampleBuffer(1) = 37
       sampleBuffer(2) = 8
       sampleBuffer(3) = 0
       sampleBuffer(4) = 41
       sampleBuffer(5) = 47
       sampleBuffer(6) = 146
       sampleBuffer(7) = 76
       Dim rdr As New BncsReader(sampleBuffer)
       Dim ping As Integer = rdr.ReadInt32()
       Console.WriteLine("{0:x8}", ping)
   End Sub
[/code]

This works correctly.  Now, if I try to initialize with an empty array, like so, I get an OverflowException:
[code]
   Sub Main()
       Dim buffer2(10) As Byte ' Contains all 0s because it has no data
       Dim rdr2 As New BncsReader(buffer2)
   End Sub
[/code]

This points to an error in MBNCSUtil, but not the one that you think.  I should be checking the [tt]length[/tt] parameter of the [tt]DataReader(Stream, int)[/tt] constructor:
[code]
       public DataReader(Stream str, int length)
       {
           if (str == null)
               throw new ArgumentNullException(Resources.param_str, Resources.streamNull);

           int moreDataLen = length;
           int curIncIndex = 0;
           m_data = new byte[moreDataLen]; // the exception is here, moreDataLen = -4
[/code]
So, you'd be getting an ArgumentOutOfRangeException instead of an OverflowException.  It still means you need to fix your code.  :P
February 28, 2010, 7:11 AM
DarkDarkDark
Well first off I'm sorry for not giving the code, I forgot to provide it. So here's my code:

[code]
Public buffer() As Byte 'Main Buffer

Public Sub SIDPING(ByVal client As Socket, ByRef SID_PING As SID_PING)

        'Redim the buffer for 8 and receive the data
        databuffer(7)

        client.BeginReceive(buffer, 0, 8, SocketFlags.None, AddressOf ReceiveCallback, buffer)

        Dim bncreader As New MBNCSUtil.BncsReader(buffer)

        SID_PING.ping = bncreader.ReadUInt32

    End Sub

Public Function databuffer(ByVal n As Integer)
        ReDim buffer(n)

End Function 'Redim DataBuffer
[/code]

It is a OverflowException, however my buffer isn't empty.

February 28, 2010, 5:12 PM
Myndfyr
Yes, it is.  It's empty because BeginReceive is non-blocking.  Your thread continues execution, immediately creating the BncsReader.  But your buffer hasn't gotten any data in it.

If you replace your BeginReceive call with Receive, I guarantee that you won't have this problem.  You'll have other problems (UI blocking, for instance), but you won't have a problem with the data and an OverflowException.

Of course, you could insist that I'm wrong, that I haven't reproduced the problem, that the 8 years of .NET programming and 6 or 7 years of Battle.net programming experience I have is irrelevant.  Lemme know.  Oh, and the fact that I wrote MBNCSUtil.  Yeah.
February 28, 2010, 9:19 PM
DarkDarkDark
okay let me check, you don't have to be a ****in dick about it and get all cocky.
February 28, 2010, 9:41 PM
DarkDarkDark
That seemed to be the problem thanks for your help.
February 28, 2010, 9:46 PM
rabbit
Screen shotted for proof.
March 1, 2010, 2:30 AM

Search