diff --git a/Vocaluxe/Base/Fonts/CFont.cs b/Vocaluxe/Base/Fonts/CFont.cs index 70232953..0c5e57cf 100644 --- a/Vocaluxe/Base/Fonts/CFont.cs +++ b/Vocaluxe/Base/Fonts/CFont.cs @@ -34,6 +34,8 @@ namespace Vocaluxe.Base.Fonts private readonly string _FilePath; + private bool _Disposed; + public CFont(string file) { _FilePath = file; @@ -135,11 +137,12 @@ namespace Vocaluxe.Base.Fonts public void Dispose() { - if (_Fonts != null) + if (!_Disposed) { - _Fonts.Dispose(); - _Fonts = null; + if (_Fonts != null) + _Fonts.Dispose(); UnloadGlyphs(); + _Disposed = true; } GC.SuppressFinalize(this); } diff --git a/Vocaluxe/Base/Fonts/CFonts.cs b/Vocaluxe/Base/Fonts/CFonts.cs index 067cabd1..0db4b25d 100644 --- a/Vocaluxe/Base/Fonts/CFonts.cs +++ b/Vocaluxe/Base/Fonts/CFonts.cs @@ -31,11 +31,13 @@ namespace Vocaluxe.Base.Fonts { private static readonly XmlWriterSettings _Settings = new XmlWriterSettings(); - private static List _Fonts; + private static readonly List _Fonts = new List(); private static int _CurrentFont; private static float _Height = 1f; + // ReSharper disable MemberCanBePrivate.Global public static int PartyModeID { get; set; } + // ReSharper restore MemberCanBePrivate.Global public static EStyle Style = EStyle.Normal; @@ -68,7 +70,14 @@ namespace Vocaluxe.Base.Fonts private static void _BuildFonts() { - _Fonts = new List(); + foreach (var font in _Fonts) + { + font.Normal.Dispose(); + font.Bold.Dispose(); + font.Italic.Dispose(); + font.BoldItalic.Dispose(); + } + _Fonts.Clear(); _CurrentFont = 0; _LoadFontList(); @@ -344,8 +353,6 @@ namespace Vocaluxe.Base.Fonts if (xmlReader == null) return; - _Fonts.Clear(); - _LoadFontFiles(xmlReader, Path.Combine(Directory.GetCurrentDirectory(), CSettings.FolderFonts)); }