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:
committed by
RoosterDragon
parent
38b579a081
commit
f0f02dff5c
@@ -18,7 +18,7 @@ using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
public class ModData
|
||||
public sealed class ModData : IDisposable
|
||||
{
|
||||
public readonly Manifest Manifest;
|
||||
public readonly ObjectCreator ObjectCreator;
|
||||
@@ -33,14 +33,17 @@ namespace OpenRA
|
||||
Lazy<Ruleset> defaultRules;
|
||||
public Ruleset DefaultRules { get { return defaultRules.Value; } }
|
||||
|
||||
public ModData(string mod)
|
||||
public ModData(string mod, bool useLoadScreen = false)
|
||||
{
|
||||
Languages = new string[0];
|
||||
Manifest = new Manifest(mod);
|
||||
ObjectCreator = new ObjectCreator(Manifest);
|
||||
LoadScreen = ObjectCreator.CreateObject<ILoadScreen>(Manifest.LoadScreen.Value);
|
||||
LoadScreen.Init(Manifest, Manifest.LoadScreen.ToDictionary(my => my.Value));
|
||||
LoadScreen.Display();
|
||||
if (useLoadScreen)
|
||||
{
|
||||
LoadScreen = ObjectCreator.CreateObject<ILoadScreen>(Manifest.LoadScreen.Value);
|
||||
LoadScreen.Init(Manifest, Manifest.LoadScreen.ToDictionary(my => my.Value));
|
||||
LoadScreen.Display();
|
||||
}
|
||||
WidgetLoader = new WidgetLoader(this);
|
||||
RulesetCache = new RulesetCache(this);
|
||||
RulesetCache.LoadingProgress += HandleLoadingProgress;
|
||||
@@ -82,8 +85,13 @@ namespace OpenRA
|
||||
// horribly when you use ModData in unexpected ways.
|
||||
ChromeMetrics.Initialize(Manifest.ChromeMetrics);
|
||||
ChromeProvider.Initialize(Manifest.Chrome);
|
||||
|
||||
if (VoxelLoader != null)
|
||||
VoxelLoader.Dispose();
|
||||
VoxelLoader = new VoxelLoader();
|
||||
|
||||
if (CursorProvider != null)
|
||||
CursorProvider.Dispose();
|
||||
CursorProvider = new CursorProvider(this);
|
||||
}
|
||||
|
||||
@@ -130,7 +138,8 @@ namespace OpenRA
|
||||
|
||||
public Map PrepareMap(string uid)
|
||||
{
|
||||
LoadScreen.Display();
|
||||
if (LoadScreen != null)
|
||||
LoadScreen.Display();
|
||||
|
||||
if (MapCache[uid].Status != MapStatus.Available)
|
||||
throw new InvalidDataException("Invalid map uid: {0}".F(uid));
|
||||
@@ -157,9 +166,21 @@ namespace OpenRA
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (LoadScreen != null)
|
||||
LoadScreen.Dispose();
|
||||
RulesetCache.Dispose();
|
||||
MapCache.Dispose();
|
||||
if (VoxelLoader != null)
|
||||
VoxelLoader.Dispose();
|
||||
if (CursorProvider != null)
|
||||
CursorProvider.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public interface ILoadScreen
|
||||
public interface ILoadScreen : IDisposable
|
||||
{
|
||||
void Init(Manifest m, Dictionary<string, string> info);
|
||||
void Display();
|
||||
|
||||
Reference in New Issue
Block a user