diff --git a/Vocaluxe/Base/CDraw.cs b/Vocaluxe/Base/CDraw.cs index 0fbc6049..7c5cd4e2 100644 --- a/Vocaluxe/Base/CDraw.cs +++ b/Vocaluxe/Base/CDraw.cs @@ -177,7 +177,9 @@ namespace Vocaluxe.Base public static void RemoveTexture(ref CTextureRef texture) { - _Draw.RemoveTexture(ref texture); + // Disposed textures call this, possibly at program end! + if (_Draw != null) + _Draw.RemoveTexture(ref texture); } public static void DrawTexture(CTextureRef texture) diff --git a/Vocaluxe/Lib/Draw/CDrawBase.cs b/Vocaluxe/Lib/Draw/CDrawBase.cs index b6b121b6..fb1e7088 100644 --- a/Vocaluxe/Lib/Draw/CDrawBase.cs +++ b/Vocaluxe/Lib/Draw/CDrawBase.cs @@ -383,6 +383,7 @@ namespace Vocaluxe.Lib.Draw _Textures.Remove(texture.ID); } } + texture.ID = -1; texture = null; } diff --git a/VocaluxeLib/Draw/CTextureRef.cs b/VocaluxeLib/Draw/CTextureRef.cs index 4083890d..df379ac1 100644 --- a/VocaluxeLib/Draw/CTextureRef.cs +++ b/VocaluxeLib/Draw/CTextureRef.cs @@ -24,7 +24,7 @@ namespace VocaluxeLib.Draw /// public class CTextureRef { - public readonly int ID; + public int ID; public string TexturePath = ""; @@ -115,6 +115,16 @@ namespace VocaluxeLib.Draw _CalcRatios(); } + ~CTextureRef() + { + if (ID >= 0) + { + //Free textures that are no longer reference + CTextureRef tmp = this; + CBase.Drawing.RemoveTexture(ref tmp); + } + } + private void _CalcRatios() { // OpenGL has a problem with partial (NPOT) textures, so we remove 1 pixel