Merge pull request #10346 from RoosterDragon/misc-fixes

Dispose fixes + misc touchups
This commit is contained in:
Paul Chote
2016-01-01 13:53:05 +00:00
15 changed files with 72 additions and 20 deletions

View File

@@ -16,6 +16,7 @@ using System.Drawing.Imaging;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Primitives; using OpenRA.Primitives;
@@ -24,6 +25,7 @@ namespace OpenRA
{ {
public static class FieldLoader public static class FieldLoader
{ {
[Serializable]
public class MissingFieldsException : YamlException public class MissingFieldsException : YamlException
{ {
public readonly string[] Missing; public readonly string[] Missing;
@@ -42,6 +44,13 @@ namespace OpenRA
Header = missing.Length > 1 ? header : headerSingle ?? header; Header = missing.Length > 1 ? header : headerSingle ?? header;
Missing = missing; Missing = missing;
} }
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("Missing", Missing);
info.AddValue("Header", Header);
}
} }
public static Func<string, Type, string, object> InvalidValueAction = (s, t, f) => public static Func<string, Type, string, object> InvalidValueAction = (s, t, f) =>

View File

@@ -17,7 +17,7 @@ using ICSharpCode.SharpZipLib.Zip.Compression;
namespace OpenRA.FileSystem namespace OpenRA.FileSystem
{ {
public class InstallShieldCABExtractor : IFolder public sealed class InstallShieldCABExtractor : IFolder
{ {
const uint FileSplit = 0x1; const uint FileSplit = 0x1;
const uint FileObfuscated = 0x2; const uint FileObfuscated = 0x2;

View File

@@ -66,7 +66,7 @@ namespace OpenRA.Chat
} }
} }
public class GlobalChat : IDisposable public sealed class GlobalChat : IDisposable
{ {
readonly IrcClient client = new IrcClient(); readonly IrcClient client = new IrcClient();
volatile Channel channel; volatile Channel channel;

View File

@@ -17,7 +17,7 @@ using OpenRA.Primitives;
namespace OpenRA.Graphics namespace OpenRA.Graphics
{ {
public class HardwareCursor : ICursor public sealed class HardwareCursor : ICursor
{ {
readonly Dictionary<string, IHardwareCursor[]> hardwareCursors = new Dictionary<string, IHardwareCursor[]>(); readonly Dictionary<string, IHardwareCursor[]> hardwareCursors = new Dictionary<string, IHardwareCursor[]>();
readonly CursorProvider cursorProvider; readonly CursorProvider cursorProvider;

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Graphics
void Tick(); void Tick();
} }
public class SoftwareCursor : ICursor public sealed class SoftwareCursor : ICursor
{ {
readonly HardwarePalette palette = new HardwarePalette(); readonly HardwarePalette palette = new HardwarePalette();
readonly Cache<string, PaletteReference> paletteReferences; readonly Cache<string, PaletteReference> paletteReferences;

View File

@@ -17,7 +17,7 @@ using SharpFont;
namespace OpenRA.Graphics namespace OpenRA.Graphics
{ {
public class SpriteFont public sealed class SpriteFont : IDisposable
{ {
static readonly Library Library = new Library(); static readonly Library Library = new Library();
@@ -150,6 +150,11 @@ namespace OpenRA.Graphics
return g; return g;
} }
public void Dispose()
{
face.Dispose();
}
} }
class GlyphInfo class GlyphInfo

View File

@@ -91,6 +91,9 @@ namespace OpenRA
public void InitializeFonts(Manifest m) public void InitializeFonts(Manifest m)
{ {
if (Fonts != null)
foreach (var font in Fonts.Values)
font.Dispose();
using (new Support.PerfTimer("SpriteFonts")) using (new Support.PerfTimer("SpriteFonts"))
{ {
if (fontSheetBuilder != null) if (fontSheetBuilder != null)
@@ -175,7 +178,7 @@ namespace OpenRA
public Size Resolution { get { return Device.WindowSize; } } public Size Resolution { get { return Device.WindowSize; } }
public interface IBatchRenderer { void Flush(); } public interface IBatchRenderer { void Flush(); }
public IBatchRenderer CurrentBatchRenderer public IBatchRenderer CurrentBatchRenderer
{ {
@@ -254,6 +257,9 @@ namespace OpenRA
tempBuffer.Dispose(); tempBuffer.Dispose();
if (fontSheetBuilder != null) if (fontSheetBuilder != null)
fontSheetBuilder.Dispose(); fontSheetBuilder.Dispose();
if (Fonts != null)
foreach (var font in Fonts.Values)
font.Dispose();
} }
public string GetClipboardText() public string GetClipboardText()

View File

@@ -124,12 +124,12 @@ namespace OpenRA.Mods.Cnc
r.EndFrame(nih); r.EndFrame(nih);
} }
public override void Dispose() protected override void Dispose(bool disposing)
{ {
if (sheet != null) if (disposing && sheet != null)
sheet.Dispose(); sheet.Dispose();
base.Dispose(); base.Dispose(disposing);
} }
} }
} }

View File

@@ -125,6 +125,7 @@ namespace OpenRA.Mods.Common.Commands
world.IssueOrder(new Order(command, world.LocalPlayer.PlayerActor, false)); world.IssueOrder(new Order(command, world.LocalPlayer.PlayerActor, false));
} }
[Serializable]
class DevException : Exception { } class DevException : Exception { }
} }
} }

View File

@@ -90,6 +90,12 @@ namespace OpenRA.Mods.Common.LoadScreens
Game.Settings.Save(); Game.Settings.Save();
} }
public virtual void Dispose() { } protected virtual void Dispose(bool disposing) { }
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
} }
} }

View File

@@ -79,12 +79,12 @@ namespace OpenRA.Mods.Common.LoadScreens
r.EndFrame(new NullInputHandler()); r.EndFrame(new NullInputHandler());
} }
public override void Dispose() protected override void Dispose(bool disposing)
{ {
if (sheet != null) if (disposing && sheet != null)
sheet.Dispose(); sheet.Dispose();
base.Dispose(); base.Dispose(disposing);
} }
} }
} }

View File

@@ -19,7 +19,7 @@ using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets namespace OpenRA.Mods.Common.Widgets
{ {
public class RadarWidget : Widget public sealed class RadarWidget : Widget, IDisposable
{ {
public string WorldInteractionController = null; public string WorldInteractionController = null;
public int AnimationLength = 5; public int AnimationLength = 5;
@@ -447,6 +447,12 @@ namespace OpenRA.Mods.Common.Widgets
base.Removed(); base.Removed();
world.Map.MapTiles.Value.CellEntryChanged -= UpdateTerrainCell; world.Map.MapTiles.Value.CellEntryChanged -= UpdateTerrainCell;
world.Map.CustomTerrain.CellEntryChanged -= UpdateTerrainCell; world.Map.CustomTerrain.CellEntryChanged -= UpdateTerrainCell;
Dispose();
}
public void Dispose()
{
radarSheet.Dispose();
} }
} }
} }

View File

@@ -304,13 +304,24 @@ namespace OpenRA.Platforms.Default
AL10.alListenerf(EFX.AL_METERS_PER_UNIT, .01f); AL10.alListenerf(EFX.AL_METERS_PER_UNIT, .01f);
} }
~OpenAlSoundEngine()
{
Game.RunAfterTick(() => Dispose(false));
}
public void Dispose() public void Dispose()
{ {
if (device == IntPtr.Zero) Game.RunAfterTick(() => Dispose(true));
return; GC.SuppressFinalize(this);
}
ALC10.alcCloseDevice(device); void Dispose(bool disposing)
device = IntPtr.Zero; {
if (device != IntPtr.Zero)
{
ALC10.alcCloseDevice(device);
device = IntPtr.Zero;
}
} }
} }

View File

@@ -31,14 +31,14 @@ namespace OpenRA.Test
{ {
Assert.That(cell, Is.EqualTo(cell.ToMPos(gridType).ToCPos(gridType))); Assert.That(cell, Is.EqualTo(cell.ToMPos(gridType).ToCPos(gridType)));
} }
catch (Exception e) catch
{ {
// Known problem on isometric mods that shouldn't be visible to players as these are outside the map. // Known problem on isometric mods that shouldn't be visible to players as these are outside the map.
if (gridType == MapGridType.RectangularIsometric && y > x) if (gridType == MapGridType.RectangularIsometric && y > x)
continue; continue;
Console.WriteLine("Coordinate {0} on grid type {1} failed to convert back.".F(cell, gridType)); Console.WriteLine("Coordinate {0} on grid type {1} failed to convert back.".F(cell, gridType));
throw e; throw;
} }
} }
} }

View File

@@ -11,9 +11,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.Serialization;
namespace OpenRA.Utility namespace OpenRA.Utility
{ {
[Serializable]
public class NoSuchCommandException : Exception public class NoSuchCommandException : Exception
{ {
public readonly string Command; public readonly string Command;
@@ -22,6 +24,12 @@ namespace OpenRA.Utility
{ {
Command = command; Command = command;
} }
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("Command", Command);
}
} }
class Program class Program