olossss / lidgren-network

Automatically exported from code.google.com/p/lidgren-network
0 stars 0 forks source link

NetQueue.cs SetCapacity(int capacity) exception "Source array was not long enough" #33

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Send a LOT of notification messages that will result in NetQueue having
to expand it's capacity.
2. When capacity tries to increase to 512 or 1024 an exception is thrown.
3.

What is the expected output? What do you see instead?
I added a try/catch around the entire SetCapcity(int capacity) block with
the catch portion as follows:

catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("NetQueue.SetCapacity() - " + ex.Message
+ " +++++stack trace ++++" + ex.StackTrace);
System.Diagnostics.Debug.WriteLine(String.Format( "capacity = {0}  m_head =
{1} m_tail = {2} m_items.Length = {3}" , capacity, m_head, m_tail,
m_items.Length ));
}

The resulting output is as follows:

capacity = 512  m_head = 105 m_tail = 106 m_items.Length = 256

NetQueue.SetCapacity() - Source array was not long enough. Check srcIndex
and length, and the array's lower bounds. +++++ Stack trace =    at
System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array
destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
   at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array
destinationArray, Int32 destinationIndex, Int32 length)
   at Lidgren.Network.NetQueue`1.SetCapacity(Int32 capacity) in
E:\TV3D65\00 Networking\Mike\32\Project
Evolution\Lidgren.Network\NetQueue.cs:line 202

The line that throws the exception is
Array.Copy(m_items, m_head, destinationArray, 0, m_size);

I'm using an older build but the source code for NetQueue.SetCapacity() in
the latest downloadable archive version has not changed.

Original issue reported on code.google.com by Hypnotro...@gmail.com on 27 Feb 2010 at 12:02

GoogleCodeExporter commented 9 years ago
Can you debug m_size and exactly what NetQueue<> are getting the error? The 
code looks 
ok, but it could be a threading problem.

Original comment by lidg...@gmail.com on 27 Feb 2010 at 9:14

GoogleCodeExporter commented 9 years ago
Interesting.  I hadn't thought about this be a threading issue but now that you
mention it, I'm certain you are correct.

It's occuring during a lot of calls to NotifyApplication  that I've added for
debugging purposes and it would be messages from multiple threads. Looking at
NetQueue in light of this Enqueue does not appear to be thread safe.  

I just got done installing some new hardware and reconfiguring my home network 
(royal
pita) but now everything is back in order and I can get back to looking at 
this. 
I'll keep you posted.

Thanks.
-Mike

Original comment by Hypnotro...@gmail.com on 1 Mar 2010 at 1:44

GoogleCodeExporter commented 9 years ago
http://www.makosoft.com/stuff/netqueue.gif

Original comment by Hypnotro...@gmail.com on 2 Mar 2010 at 8:45