graphics resource tracking optimization
parent
0781a99273
commit
e93f4f09bb
|
@ -18,7 +18,7 @@ namespace MoonWorks.Graphics
|
|||
|
||||
public bool IsDisposed { get; private set; }
|
||||
|
||||
private readonly List<WeakReference<GraphicsResource>> resources = new List<WeakReference<GraphicsResource>>();
|
||||
private readonly HashSet<WeakReference<GraphicsResource>> resources = new HashSet<WeakReference<GraphicsResource>>();
|
||||
|
||||
public GraphicsDevice(
|
||||
Backend preferredBackend,
|
||||
|
@ -237,10 +237,9 @@ namespace MoonWorks.Graphics
|
|||
{
|
||||
lock (resources)
|
||||
{
|
||||
for (var i = resources.Count - 1; i >= 0; i--)
|
||||
foreach (var weakReference in resources)
|
||||
{
|
||||
var resource = resources[i];
|
||||
if (resource.TryGetTarget(out var target))
|
||||
if (weakReference.TryGetTarget(out var target))
|
||||
{
|
||||
target.Dispose();
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace MoonWorks.Graphics
|
|||
public bool IsDisposed { get; private set; }
|
||||
protected abstract Action<IntPtr, IntPtr> QueueDestroyFunction { get; }
|
||||
|
||||
private WeakReference<GraphicsResource> selfReference;
|
||||
internal WeakReference<GraphicsResource> weakReference;
|
||||
|
||||
public GraphicsResource(GraphicsDevice device, bool trackResource = true)
|
||||
{
|
||||
|
@ -18,8 +18,8 @@ namespace MoonWorks.Graphics
|
|||
|
||||
if (trackResource)
|
||||
{
|
||||
selfReference = new WeakReference<GraphicsResource>(this);
|
||||
Device.AddResourceReference(selfReference);
|
||||
weakReference = new WeakReference<GraphicsResource>(this);
|
||||
Device.AddResourceReference(weakReference);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,11 +27,11 @@ namespace MoonWorks.Graphics
|
|||
{
|
||||
if (!IsDisposed)
|
||||
{
|
||||
if (selfReference != null)
|
||||
if (weakReference != null)
|
||||
{
|
||||
QueueDestroyFunction(Device.Handle, Handle);
|
||||
Device.RemoveResourceReference(selfReference);
|
||||
selfReference = null;
|
||||
Device.RemoveResourceReference(weakReference);
|
||||
weakReference = null;
|
||||
}
|
||||
|
||||
IsDisposed = true;
|
||||
|
|
Loading…
Reference in New Issue