Fixed the correct value passed to GC on Dispose of ParticleBuffer (#580) (#581)

More info available in #580
This commit is contained in:
luisfb
2018-12-27 23:14:51 +10:00
committed by Dylan Wilson
parent 8e91b622da
commit 7a524a156c
@@ -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
}
}
}
}
}