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

@@ -140,7 +140,10 @@ namespace OpenRA
orderManager.World = new World(map, orderManager, isShellmap);
orderManager.World.Timestep = Timestep;
}
if (worldRenderer != null)
worldRenderer.Dispose();
worldRenderer = new WorldRenderer(orderManager.World);
using (new PerfTimer("LoadComplete"))
orderManager.World.LoadComplete(worldRenderer);
@@ -215,7 +218,7 @@ namespace OpenRA
Settings.Graphics.Renderer = r;
try
{
Renderer.Initialize(Settings.Graphics.Mode);
Renderer = new Renderer(Settings.Graphics, Settings.Server);
break;
}
catch (Exception e)
@@ -225,8 +228,6 @@ namespace OpenRA
}
}
Renderer = new Renderer();
try
{
Sound.Create(Settings.Sound.Engine);
@@ -257,12 +258,18 @@ namespace OpenRA
BeforeGameStart = () => { };
Ui.ResetAll();
if (worldRenderer != null)
worldRenderer.Dispose();
worldRenderer = null;
if (server != null)
server.Shutdown();
if (orderManager != null)
orderManager.Dispose();
if (modData != null)
modData.Dispose();
modData = null;
// Fall back to default if the mod doesn't exist
if (!ModMetadata.AllMods.ContainsKey(mod))
mod = new GameSettings().Mod;
@@ -274,7 +281,7 @@ namespace OpenRA
Sound.StopVideo();
Sound.Initialize();
modData = new ModData(mod);
modData = new ModData(mod, true);
Renderer.InitializeFonts(modData.Manifest);
modData.InitializeLoaders();
using (new PerfTimer("LoadMaps"))
@@ -632,8 +639,12 @@ namespace OpenRA
if (orderManager != null)
orderManager.Dispose();
}
Renderer.Device.Dispose();
if (worldRenderer != null)
worldRenderer.Dispose();
modData.Dispose();
ChromeProvider.Deinitialize();
Renderer.Dispose();
OnQuit();