minor cleanup on mesh decompress code

0.9.1.0-post-fixes
UbitUmarov 2019-04-02 10:13:26 +01:00
parent 2739b2f5cc
commit ba66d2d3c1
3 changed files with 19 additions and 42 deletions

View File

@ -563,13 +563,11 @@ namespace OpenSim.Region.ClientStack.Linden
nsides = 0;
OSD decodedMeshOsd = new OSD();
byte[] meshBytes = new byte[size];
System.Buffer.BlockCopy(data, offset, meshBytes, 0, size);
try
{
using (MemoryStream inMs = new MemoryStream(meshBytes))
{
using (MemoryStream outMs = new MemoryStream())
{
using (MemoryStream inMs = new MemoryStream(data, offset, size))
{
using (DeflateStream decompressionStream = new DeflateStream(inMs, CompressionMode.Decompress))
{
@ -579,13 +577,10 @@ namespace OpenSim.Region.ClientStack.Linden
while ((readLen = decompressionStream.Read(readBuffer, 0, readBuffer.Length)) > 0)
outMs.Write(readBuffer, 0, readLen);
}
}
outMs.Seek(0, SeekOrigin.Begin);
byte[] decompressedBuf = outMs.GetBuffer();
decodedMeshOsd = OSDParser.DeserializeLLSDBinary(decompressedBuf);
}
}
decodedMeshOsd = OSDParser.DeserializeLLSDBinary(outMs);
}
}
catch
@ -630,29 +625,24 @@ namespace OpenSim.Region.ClientStack.Linden
nhulls = 1;
OSD decodedMeshOsd = new OSD();
byte[] meshBytes = new byte[size];
System.Buffer.BlockCopy(data, offset, meshBytes, 0, size);
try
{
using (MemoryStream inMs = new MemoryStream(meshBytes))
using (MemoryStream outMs = new MemoryStream(4 * size))
{
using (MemoryStream outMs = new MemoryStream())
using (MemoryStream inMs = new MemoryStream(data, offset, size))
{
using (DeflateStream decompressionStream = new DeflateStream(inMs, CompressionMode.Decompress))
{
byte[] readBuffer = new byte[2048];
byte[] readBuffer = new byte[8192];
inMs.Read(readBuffer, 0, 2); // skip first 2 bytes in header
int readLen = 0;
while ((readLen = decompressionStream.Read(readBuffer, 0, readBuffer.Length)) > 0)
outMs.Write(readBuffer, 0, readLen);
}
}
outMs.Seek(0, SeekOrigin.Begin);
byte[] decompressedBuf = outMs.GetBuffer();
decodedMeshOsd = OSDParser.DeserializeLLSDBinary(decompressedBuf);
}
}
decodedMeshOsd = OSDParser.DeserializeLLSDBinary(outMs);
}
}
catch

View File

@ -597,28 +597,22 @@ namespace OpenSim.Region.PhysicsModule.Meshing
{
OSD decodedOsd = null;
using (MemoryStream inMs = new MemoryStream(meshBytes))
{
using (MemoryStream outMs = new MemoryStream())
{
using (MemoryStream inMs = new MemoryStream(meshBytes))
{
using (DeflateStream decompressionStream = new DeflateStream(inMs, CompressionMode.Decompress))
{
byte[] readBuffer = new byte[2048];
byte[] readBuffer = new byte[8192];
inMs.Read(readBuffer, 0, 2); // skip first 2 bytes in header
int readLen = 0;
while ((readLen = decompressionStream.Read(readBuffer, 0, readBuffer.Length)) > 0)
outMs.Write(readBuffer, 0, readLen);
outMs.Flush();
}
}
outMs.Seek(0, SeekOrigin.Begin);
byte[] decompressedBuf = outMs.GetBuffer();
decodedOsd = OSDParser.DeserializeLLSDBinary(decompressedBuf);
}
}
decodedOsd = OSDParser.DeserializeLLSDBinary(outMs);
}
return decodedOsd;
}

View File

@ -425,31 +425,24 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
return false; // no mesh data in asset
OSD decodedMeshOsd = new OSD();
byte[] meshBytes = new byte[physSize];
System.Buffer.BlockCopy(primShape.SculptData, physOffset, meshBytes, 0, physSize);
try
{
using (MemoryStream inMs = new MemoryStream(meshBytes))
using (MemoryStream outMs = new MemoryStream(4 * physSize))
{
using (MemoryStream outMs = new MemoryStream())
using (MemoryStream inMs = new MemoryStream(primShape.SculptData, physOffset, physSize))
{
using (DeflateStream decompressionStream = new DeflateStream(inMs, CompressionMode.Decompress))
{
byte[] readBuffer = new byte[2048];
byte[] readBuffer = new byte[8192];
inMs.Read(readBuffer, 0, 2); // skip first 2 bytes in header
int readLen = 0;
while ((readLen = decompressionStream.Read(readBuffer, 0, readBuffer.Length)) > 0)
outMs.Write(readBuffer, 0, readLen);
}
}
outMs.Seek(0, SeekOrigin.Begin);
byte[] decompressedBuf = outMs.GetBuffer();
decodedMeshOsd = OSDParser.DeserializeLLSDBinary(decompressedBuf);
}
}
decodedMeshOsd = OSDParser.DeserializeLLSDBinary(outMs);
}
}
catch (Exception e)