In the packetpool, if we encounter a data block that somehow wasn't retrieved via GetDataBlock() then create a new stack instead of throwing an exception

bulletsim
Justin Clark-Casey (justincc) 2011-07-31 02:30:40 +01:00
parent d041276517
commit 450bdb3657
1 changed files with 11 additions and 6 deletions

View File

@ -144,6 +144,7 @@ namespace OpenSim.Framework
m_log.WarnFormat("[PACKETPOOL]: Failed to get packet of type {0}", type); m_log.WarnFormat("[PACKETPOOL]: Failed to get packet of type {0}", type);
else else
packet.FromBytes(bytes, ref i, ref packetEnd, zeroBuffer); packet.FromBytes(bytes, ref i, ref packetEnd, zeroBuffer);
return packet; return packet;
} }
@ -160,19 +161,18 @@ namespace OpenSim.Framework
case PacketType.ObjectUpdate: case PacketType.ObjectUpdate:
ObjectUpdatePacket oup = (ObjectUpdatePacket)packet; ObjectUpdatePacket oup = (ObjectUpdatePacket)packet;
foreach (ObjectUpdatePacket.ObjectDataBlock oupod in foreach (ObjectUpdatePacket.ObjectDataBlock oupod in oup.ObjectData)
oup.ObjectData)
ReturnDataBlock<ObjectUpdatePacket.ObjectDataBlock>(oupod); ReturnDataBlock<ObjectUpdatePacket.ObjectDataBlock>(oupod);
oup.ObjectData = null; oup.ObjectData = null;
break; break;
case PacketType.ImprovedTerseObjectUpdate: case PacketType.ImprovedTerseObjectUpdate:
ImprovedTerseObjectUpdatePacket itoup = ImprovedTerseObjectUpdatePacket itoup = (ImprovedTerseObjectUpdatePacket)packet;
(ImprovedTerseObjectUpdatePacket)packet;
foreach (ImprovedTerseObjectUpdatePacket.ObjectDataBlock foreach (ImprovedTerseObjectUpdatePacket.ObjectDataBlock itoupod in itoup.ObjectData)
itoupod in itoup.ObjectData)
ReturnDataBlock<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>(itoupod); ReturnDataBlock<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>(itoupod);
itoup.ObjectData = null; itoup.ObjectData = null;
break; break;
} }
@ -194,6 +194,7 @@ namespace OpenSim.Framework
{ {
pool[type] = new Stack<Packet>(); pool[type] = new Stack<Packet>();
} }
if ((pool[type]).Count < 50) if ((pool[type]).Count < 50)
{ {
(pool[type]).Push(packet); (pool[type]).Push(packet);
@ -223,6 +224,7 @@ namespace OpenSim.Framework
{ {
DataBlocks[typeof(T)] = new Stack<Object>(); DataBlocks[typeof(T)] = new Stack<Object>();
} }
return new T(); return new T();
} }
} }
@ -234,6 +236,9 @@ namespace OpenSim.Framework
lock (DataBlocks) lock (DataBlocks)
{ {
if (!DataBlocks.ContainsKey(typeof(T)))
DataBlocks[typeof(T)] = new Stack<Object>();
if (DataBlocks[typeof(T)].Count < 50) if (DataBlocks[typeof(T)].Count < 50)
DataBlocks[typeof(T)].Push(block); DataBlocks[typeof(T)].Push(block);
} }