From 7a524a156ce7d0df8ef00fade7d98cf916149900 Mon Sep 17 00:00:00 2001 From: luisfb Date: Thu, 27 Dec 2018 11:14:51 -0200 Subject: [PATCH 1/2] Fixed the correct value passed to GC on Dispose of ParticleBuffer (#580) (#581) More info available in #580 --- Source/MonoGame.Extended.Particles/ParticleBuffer.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Source/MonoGame.Extended.Particles/ParticleBuffer.cs b/Source/MonoGame.Extended.Particles/ParticleBuffer.cs index e1f674d9..2e410fa8 100644 --- a/Source/MonoGame.Extended.Particles/ParticleBuffer.cs +++ b/Source/MonoGame.Extended.Particles/ParticleBuffer.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Runtime.InteropServices; namespace MonoGame.Extended.Particles @@ -18,9 +18,8 @@ namespace MonoGame.Extended.Particles public unsafe ParticleBuffer(int size) { Size = size; - // add one extra spot in memory for margin between head and tail - // so the iterator can see that it's at the end _nativePointer = Marshal.AllocHGlobal(SizeInBytes); + BufferEnd = (Particle*) (_nativePointer + SizeInBytes); Head = (Particle*) _nativePointer; Tail = (Particle*) _nativePointer; @@ -40,7 +39,7 @@ namespace MonoGame.Extended.Particles public int Available => Size - Count; // current number of particles public int Count { get; private set; } - // total size of the buffer + // total size of the buffer (add one extra spot in memory for margin between head and tail so the iterator can see that it's at the end) public int SizeInBytes => Particle.SizeInBytes*(Size + 1); // total size of active particles public int ActiveSizeInBytes => Particle.SizeInBytes*Count; @@ -51,8 +50,7 @@ namespace MonoGame.Extended.Particles { Marshal.FreeHGlobal(_nativePointer); _disposed = true; - - GC.RemoveMemoryPressure(Particle.SizeInBytes*Size); + GC.RemoveMemoryPressure(SizeInBytes); } GC.SuppressFinalize(this); @@ -151,4 +149,4 @@ namespace MonoGame.Extended.Particles } } } -} \ No newline at end of file +} From 6295c8dc365accf8692a55859190ca3114614cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Tom=C3=A1s=20Gracia?= Date: Fri, 28 Dec 2018 16:21:30 +0800 Subject: [PATCH 2/2] Fixed ContentReaderExtensions (#575) Fixes #573 --- .../Content/ContentReaderExtensions.cs | 17 ++++++++------ .../Content/ContentReaderExtensionsTests.cs | 23 +++++++++++++++++++ .../MonoGame.Extended.Tests.csproj | 5 +++- 3 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 Source/Tests/MonoGame.Extended.Tests/Content/ContentReaderExtensionsTests.cs diff --git a/Source/MonoGame.Extended/Content/ContentReaderExtensions.cs b/Source/MonoGame.Extended/Content/ContentReaderExtensions.cs index f4a56b84..ef33841f 100644 --- a/Source/MonoGame.Extended/Content/ContentReaderExtensions.cs +++ b/Source/MonoGame.Extended/Content/ContentReaderExtensions.cs @@ -20,17 +20,20 @@ namespace MonoGame.Extended.Content var assetDirectory = Path.GetDirectoryName(contentReader.AssetName); var assetName = Path.Combine(assetDirectory, relativeName).Replace('\\', '/'); - var ellipseIndex = assetName.IndexOf("/../", StringComparison.Ordinal); + return ShortenRelativePath(assetName); + } + + public static string ShortenRelativePath(string relativePath) + { + var ellipseIndex = relativePath.IndexOf("/../", StringComparison.Ordinal); while (ellipseIndex != -1) { - var lastDirectoryIndex = assetName.LastIndexOf('/', ellipseIndex - 1); - if (lastDirectoryIndex == -1) - lastDirectoryIndex = 0; - assetName = assetName.Remove(lastDirectoryIndex, ellipseIndex + 4); - ellipseIndex = assetName.IndexOf("/../", StringComparison.Ordinal); + var lastDirectoryIndex = relativePath.LastIndexOf('/', ellipseIndex - 1) + 1; + relativePath = relativePath.Remove(lastDirectoryIndex, ellipseIndex + 4 - lastDirectoryIndex); + ellipseIndex = relativePath.IndexOf("/../", StringComparison.Ordinal); } - return assetName; + return relativePath; } } } \ No newline at end of file diff --git a/Source/Tests/MonoGame.Extended.Tests/Content/ContentReaderExtensionsTests.cs b/Source/Tests/MonoGame.Extended.Tests/Content/ContentReaderExtensionsTests.cs new file mode 100644 index 00000000..e1c701d6 --- /dev/null +++ b/Source/Tests/MonoGame.Extended.Tests/Content/ContentReaderExtensionsTests.cs @@ -0,0 +1,23 @@ +using System; +using System.Linq; +using MonoGame.Extended.Collections; +using MonoGame.Extended.Content; +using Xunit; + +namespace MonoGame.Extended.Tests.Content +{ + public class ContentReaderExtensionsTests + { + [Theory] + [InlineData("testsuperdir/testsubdir1/testsubdir2/resource", "testsuperdir/testsubdir1/testsubdir2/resource")] + [InlineData("testsuperdir/testsubdir1/../testsubdir2/resource","testsuperdir/testsubdir2/resource")] + [InlineData("testsuperdir/../resource","resource")] + [InlineData("../testsuperdir/testsubdir1/../testsubdir2/resource","../testsuperdir/testsubdir2/resource")] + [InlineData("testsuperdir/testsubdir1/testsubdir2/../../testsubdir3/resource","testsuperdir/testsubdir3/resource")] + [InlineData("testsuperdir/testsubdir1/../testsubdir2/../testsubdir3/resource", "testsuperdir/testsubdir3/resource")] + public void ContentReaderExtensions_ShortenRelativePath(string input, string expectedoutput) + { + Assert.True(ContentReaderExtensions.ShortenRelativePath(input) == expectedoutput); + } + } +} \ No newline at end of file diff --git a/Source/Tests/MonoGame.Extended.Tests/MonoGame.Extended.Tests.csproj b/Source/Tests/MonoGame.Extended.Tests/MonoGame.Extended.Tests.csproj index e0453315..bd8b772d 100644 --- a/Source/Tests/MonoGame.Extended.Tests/MonoGame.Extended.Tests.csproj +++ b/Source/Tests/MonoGame.Extended.Tests/MonoGame.Extended.Tests.csproj @@ -1,4 +1,4 @@ - + netcoreapp2.0 false @@ -17,4 +17,7 @@ + + +