Avoid a globally shared SheetBuilder in SpriteFont.

A globally shared sheet builder leaks memory and resources between mod switches. Instead, we create and inject the sheet builder during mod startup to ensure we still share the builder across all fonts, but can reclaim it when the mod is unloaded.
This commit is contained in:
RoosterDragon
2015-01-14 22:33:58 +00:00
parent 398af8e513
commit c313c52e96
3 changed files with 24 additions and 17 deletions

View File

@@ -31,8 +31,8 @@ namespace OpenRA.Graphics
public sealed class SheetBuilder : IDisposable
{
public readonly SheetType Type;
readonly List<Sheet> sheets = new List<Sheet>();
readonly SheetType type;
readonly Func<Sheet> allocateSheet;
Sheet current;
@@ -54,7 +54,7 @@ namespace OpenRA.Graphics
public SheetBuilder(SheetType t, Func<Sheet> allocateSheet)
{
channel = TextureChannel.Red;
type = t;
Type = t;
current = allocateSheet();
sheets.Add(current);
this.allocateSheet = allocateSheet;
@@ -93,7 +93,7 @@ namespace OpenRA.Graphics
TextureChannel? NextChannel(TextureChannel t)
{
var nextChannel = (int)t + (int)type;
var nextChannel = (int)t + (int)Type;
if (nextChannel > (int)TextureChannel.Alpha)
return null;