Fixed memory leak in RPF Explorer

This commit is contained in:
dexy 2022-07-30 21:54:21 +10:00
parent cf81aebbb7
commit ba16eab570
7 changed files with 41 additions and 18 deletions

View File

@ -898,19 +898,21 @@ namespace CodeWalker.GameFiles
{
using (DeflateStream ds = new DeflateStream(new MemoryStream(bytes), CompressionMode.Decompress))
{
MemoryStream outstr = new MemoryStream();
ds.CopyTo(outstr);
byte[] deflated = outstr.GetBuffer();
byte[] outbuf = new byte[outstr.Length]; //need to copy to the right size buffer for output.
Array.Copy(deflated, outbuf, outbuf.Length);
if (outbuf.Length <= bytes.Length)
using (var outstr = new MemoryStream())
{
LastError = "Warning: Decompressed data was smaller than compressed data...";
//return null; //could still be OK for tiny things!
}
ds.CopyTo(outstr);
byte[] deflated = outstr.GetBuffer();
byte[] outbuf = new byte[outstr.Length]; //need to copy to the right size buffer for output.
Buffer.BlockCopy(deflated, 0, outbuf, 0, outbuf.Length);
return outbuf;
if (outbuf.Length <= bytes.Length)
{
LastError = "Warning: Decompressed data was smaller than compressed data...";
//return null; //could still be OK for tiny things!
}
return outbuf;
}
}
}
catch (Exception ex)
@ -924,13 +926,15 @@ namespace CodeWalker.GameFiles
{
using (MemoryStream ms = new MemoryStream())
{
DeflateStream ds = new DeflateStream(ms, CompressionMode.Compress, true);
ds.Write(data, 0, data.Length);
ds.Close();
byte[] deflated = ms.GetBuffer();
byte[] outbuf = new byte[ms.Length]; //need to copy to the right size buffer...
Array.Copy(deflated, outbuf, outbuf.Length);
return outbuf;
using (var ds = new DeflateStream(ms, CompressionMode.Compress, true))
{
ds.Write(data, 0, data.Length);
ds.Close();
byte[] deflated = ms.GetBuffer();
byte[] outbuf = new byte[ms.Length]; //need to copy to the right size buffer...
Buffer.BlockCopy(deflated, 0, outbuf, 0, outbuf.Length);
return outbuf;
}
}
}

View File

@ -46,6 +46,7 @@ namespace CodeWalker.Rendering
try
{
//SharpDX.Configuration.EnableObjectTracking = true;
SwapChainDescription scd = new SwapChainDescription()
{
@ -154,12 +155,18 @@ namespace CodeWalker.Rendering
dxform.CleanupScene();
if (context != null) context.ClearState();
//dipose of all objects
if (depthview != null) depthview.Dispose();
if (depthbuffer != null) depthbuffer.Dispose();
if (targetview != null) targetview.Dispose();
if (backbuffer != null) backbuffer.Dispose();
if (swapchain != null) swapchain.Dispose();
if (context != null) context.Dispose();
//var objs = SharpDX.Diagnostics.ObjectTracker.FindActiveObjects();
if (device != null) device.Dispose();
GC.Collect();

View File

@ -323,6 +323,7 @@ namespace CodeWalker.Rendering
cacheitems.Clear();
itemsToUnload = new ConcurrentQueue<TVal>();
keysToInvalidate = new ConcurrentQueue<TKey>();
CacheUse = 0;
}

View File

@ -235,6 +235,8 @@ namespace CodeWalker.Rendering
bsAdd.Dispose();
rsSolid.Dispose();
rsWireframe.Dispose();
rsSolidDblSided.Dispose();
rsWireframeDblSided.Dispose();
Widgets.Dispose();
Paths.Dispose();
@ -284,6 +286,8 @@ namespace CodeWalker.Rendering
public void BeginFrame(DeviceContext context, double currentRealTime, float elapsedTime)
{
if (disposed) return;
CurrentRealTime = currentRealTime;
CurrentElapsedTime = elapsedTime;

View File

@ -1025,6 +1025,7 @@ namespace CodeWalker.Rendering
texsampler.Dispose();
texsampleranis.Dispose();
texsamplertnt.Dispose();
texsamplertntyft.Dispose();
foreach (InputLayout layout in layouts.Values)
{

View File

@ -340,6 +340,7 @@ namespace CodeWalker.Rendering
texsampler.Dispose();
texsampleranis.Dispose();
layout.Dispose();

View File

@ -415,6 +415,11 @@ namespace CodeWalker.Rendering
texsampler.Dispose();
texsampler = null;
}
if (texsamplerc != null)
{
texsamplerc.Dispose();
texsamplerc = null;
}
foreach (InputLayout layout in layouts.Values)
{