Skip to content

Commit

Permalink
keep track of uncached textures for dispose (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmriggs committed May 25, 2021
1 parent c8e077c commit fc27606
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions ACViewer/Render/TextureCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class TextureCache

public static Dictionary<uint, Texture2D> Textures { get; set; }

public static List<Texture2D> Uncached { get; set; }

public static bool UseMipMaps { get; set; }

static TextureCache()
Expand All @@ -33,16 +35,26 @@ static TextureCache()

public static void Init(bool dispose = true)
{
if (dispose && Textures != null)
if (dispose)
{
foreach (var texture in Textures.Values)
texture.Dispose();
if (Textures != null)
{
foreach (var texture in Textures.Values)
texture.Dispose();
}

if (Uncached != null)
{
foreach (var texture in Uncached)
texture.Dispose();
}
}

GfxObjCache.Init();
SetupCache.Init();

Textures = new Dictionary<uint, Texture2D>();
Uncached = new List<Texture2D>();
}

private static Texture2D LoadTexture(uint textureID, bool useDummy = false, Surface surface = null, Dictionary<int, uint> customPaletteColors = null)
Expand Down Expand Up @@ -435,6 +447,8 @@ private static Texture2D GetTexture(uint textureID, Surface surface = null, Dict

if (useCache)
Textures.Add(textureID, texture);
else
Uncached.Add(texture);

return texture;
}
Expand Down

0 comments on commit fc27606

Please sign in to comment.