From 77a44b2c8e1b8e8fb0795b35f24bb4846e211f98 Mon Sep 17 00:00:00 2001 From: thefiddler Date: Wed, 23 Jul 2014 09:21:20 +0200 Subject: [PATCH] [OpenTK] Add allocated resource registry --- Source/OpenTK/Platform/PlatformFactoryBase.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Source/OpenTK/Platform/PlatformFactoryBase.cs b/Source/OpenTK/Platform/PlatformFactoryBase.cs index 40dc0c1c..95f1a8fd 100644 --- a/Source/OpenTK/Platform/PlatformFactoryBase.cs +++ b/Source/OpenTK/Platform/PlatformFactoryBase.cs @@ -28,6 +28,7 @@ #endregion using System; +using System.Collections.Generic; using System.Diagnostics; using OpenTK.Graphics; using OpenTK.Input; @@ -42,12 +43,27 @@ namespace OpenTK.Platform /// abstract class PlatformFactoryBase : IPlatformFactory { + static readonly object sync = new object(); + readonly List Resources = new List(); + protected bool IsDisposed; public PlatformFactoryBase() { } + #region Protected Members + + protected void RegisterResource(IDisposable resource) + { + lock (sync) + { + Resources.Add(resource); + } + } + + #endregion + #region IPlatformFactory Members public abstract INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device); @@ -96,6 +112,13 @@ namespace OpenTK.Platform { if (manual) { + lock (sync) + { + foreach (var resource in Resources) + { + resource.Dispose(); + } + } } else {