From f2a08876c7d27bab965b074aa79092a44d5f4bbb Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Thu, 18 Apr 2013 12:20:08 +0200 Subject: [PATCH] Support for disposing textures. --- spine-csharp/src/Atlas.cs | 8 ++++++++ spine-unity/Assets/Plugins/Spine/AtlasAsset.cs | 3 +++ spine-xna/src/XnaTextureLoader.cs | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/spine-csharp/src/Atlas.cs b/spine-csharp/src/Atlas.cs index 7ab0af481..421668136 100644 --- a/spine-csharp/src/Atlas.cs +++ b/spine-csharp/src/Atlas.cs @@ -30,6 +30,7 @@ namespace Spine { public class Atlas { List pages = new List(); List regions = new List(); + TextureLoader textureLoader; public Atlas (String path, TextureLoader textureLoader) { using (StreamReader reader = new StreamReader(path)) { @@ -47,6 +48,7 @@ namespace Spine { private void Load (TextReader reader, String imagesDir, TextureLoader textureLoader) { if (textureLoader == null) throw new ArgumentNullException("textureLoader cannot be null."); + this.textureLoader = textureLoader; String[] tuple = new String[4]; AtlasPage page = null; @@ -163,6 +165,11 @@ namespace Spine { if (regions[i].name == name) return regions[i]; return null; } + + public void Dispose () { + for (int i = 0, n = pages.Count; i < n; i++) + textureLoader.Unload(pages[i].texture); + } } public enum Format { @@ -217,5 +224,6 @@ namespace Spine { public interface TextureLoader { void Load (AtlasPage page, String path); + void Unload (Object texture); } } diff --git a/spine-unity/Assets/Plugins/Spine/AtlasAsset.cs b/spine-unity/Assets/Plugins/Spine/AtlasAsset.cs index ab9ad7a39..3b46ad44d 100644 --- a/spine-unity/Assets/Plugins/Spine/AtlasAsset.cs +++ b/spine-unity/Assets/Plugins/Spine/AtlasAsset.cs @@ -74,4 +74,7 @@ public class SingleTextureLoader : TextureLoader { page.width = material.mainTexture.width; page.height = material.mainTexture.height; } + + public void Unload (object texture) { + } } diff --git a/spine-xna/src/XnaTextureLoader.cs b/spine-xna/src/XnaTextureLoader.cs index 88657a2c4..dd65aeb10 100644 --- a/spine-xna/src/XnaTextureLoader.cs +++ b/spine-xna/src/XnaTextureLoader.cs @@ -31,6 +31,7 @@ using Microsoft.Xna.Framework.Graphics; namespace Spine { public class XnaTextureLoader : TextureLoader { GraphicsDevice device; + public XnaTextureLoader (GraphicsDevice device) { this.device = device; } @@ -41,5 +42,9 @@ namespace Spine { page.width = texture.Width; page.height = texture.Height; } + + public void Unload (Object texture) { + ((Texture2D)texture).Dispose(); + } } }