Dispose of graphics resources deterministically.

Textures, FrameBuffers and VertexBuffers allocated by the Sdl2 Renderer were only being released via finalizers. This could lead to OpenGL out of memory errors since resources may not be cleaned up in a timely manner. To avoid this, IDisposable has been implemented and transitively applied to classes that use these resources.

As a side-effect some static state is no longer static, particularly in Renderer, in order to facilitate this change and just for nicer design in general.

Also dispose some bitmaps.
This commit is contained in:
RoosterDragon
2014-10-24 18:21:30 +01:00
committed by RoosterDragon
parent 38b579a081
commit f0f02dff5c
31 changed files with 371 additions and 128 deletions

View File

@@ -23,6 +23,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Widget modList;
ButtonWidget modTemplate;
ModMetadata[] allMods;
readonly SheetBuilder sheetBuilder;
ModMetadata selectedMod;
string selectedAuthor;
string selectedDescription;
@@ -63,7 +64,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return ret;
};
var sheetBuilder = new SheetBuilder(SheetType.BGRA);
sheetBuilder = new SheetBuilder(SheetType.BGRA);
previews = new Dictionary<string, Sprite>();
logos = new Dictionary<string, Sprite>();
allMods = ModMetadata.AllMods.Values.Where(m => m.Id != "modchooser")
@@ -75,21 +76,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
try
{
var preview = new Bitmap(Platform.ResolvePath(".", "mods", mod.Id, "preview.png"));
if (preview.Width != 296 || preview.Height != 196)
continue;
previews.Add(mod.Id, sheetBuilder.Add(preview));
using (var preview = new Bitmap(Platform.ResolvePath(".", "mods", mod.Id, "preview.png")))
if (preview.Width == 296 && preview.Height == 196)
previews.Add(mod.Id, sheetBuilder.Add(preview));
}
catch (Exception) { }
try
{
var logo = new Bitmap(Platform.ResolvePath(".", "mods", mod.Id, "logo.png"));
if (logo.Width != 96 || logo.Height != 96)
continue;
logos.Add(mod.Id, sheetBuilder.Add(logo));
using (var logo = new Bitmap(Platform.ResolvePath(".", "mods", mod.Id, "logo.png")))
if (logo.Width == 96 && logo.Height == 96)
logos.Add(mod.Id, sheetBuilder.Add(logo));
}
catch (Exception) { }
}
@@ -155,11 +152,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
modOffset = selectedIndex - 4;
}
static void LoadMod(ModMetadata mod)
void LoadMod(ModMetadata mod)
{
Game.RunAfterTick(() =>
{
Ui.CloseWindow();
sheetBuilder.Dispose();
Game.InitializeMod(mod.Id, null);
});
}