From ec01f6331772053bd0493054e53366f617676f67 Mon Sep 17 00:00:00 2001 From: Gustas <37534529+PunkPun@users.noreply.github.com> Date: Mon, 10 Mar 2025 18:45:14 +0200 Subject: [PATCH] Add missing dispose calls --- OpenRA.Mods.Cnc/Traits/World/ChronoVortexRenderer.cs | 8 +++++++- .../Traits/World/RenderPostProcessPassBase.cs | 7 ++++++- OpenRA.Mods.Common/Widgets/ColorMixerWidget.cs | 6 ++++++ OpenRA.Mods.Common/Widgets/HueSliderWidget.cs | 9 ++++++++- OpenRA.Mods.Common/Widgets/Logic/EncyclopediaLogic.cs | 10 ++++++++++ OpenRA.Mods.Common/Widgets/VideoPlayerWidget.cs | 10 +++++++++- 6 files changed, 46 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Cnc/Traits/World/ChronoVortexRenderer.cs b/OpenRA.Mods.Cnc/Traits/World/ChronoVortexRenderer.cs index e0ed8b4b65..c5fcb07e71 100644 --- a/OpenRA.Mods.Cnc/Traits/World/ChronoVortexRenderer.cs +++ b/OpenRA.Mods.Cnc/Traits/World/ChronoVortexRenderer.cs @@ -23,7 +23,7 @@ namespace OpenRA.Mods.Cnc.Traits public override object Create(ActorInitializer init) { return new ChronoVortexRenderer(init.Self); } } - public sealed class ChronoVortexRenderer : IRenderPostProcessPass + public sealed class ChronoVortexRenderer : IRenderPostProcessPass, INotifyActorDisposing { readonly Renderer renderer; readonly IShader shader; @@ -105,5 +105,11 @@ namespace OpenRA.Mods.Cnc.Traits vortices.Clear(); } + + void INotifyActorDisposing.Disposing(Actor self) + { + vortexSheet.Dispose(); + vortexBuffer.Dispose(); + } } } diff --git a/OpenRA.Mods.Common/Traits/World/RenderPostProcessPassBase.cs b/OpenRA.Mods.Common/Traits/World/RenderPostProcessPassBase.cs index 558a6db3e0..cce3f315d7 100644 --- a/OpenRA.Mods.Common/Traits/World/RenderPostProcessPassBase.cs +++ b/OpenRA.Mods.Common/Traits/World/RenderPostProcessPassBase.cs @@ -14,7 +14,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { - public abstract class RenderPostProcessPassBase : IRenderPostProcessPass + public abstract class RenderPostProcessPassBase : IRenderPostProcessPass, INotifyActorDisposing { readonly Renderer renderer; readonly IShader shader; @@ -52,5 +52,10 @@ namespace OpenRA.Mods.Common.Traits protected abstract bool Enabled { get; } protected abstract void PrepareRender(WorldRenderer wr, IShader shader); + + void INotifyActorDisposing.Disposing(Actor self) + { + buffer.Dispose(); + } } } diff --git a/OpenRA.Mods.Common/Widgets/ColorMixerWidget.cs b/OpenRA.Mods.Common/Widgets/ColorMixerWidget.cs index 26334df641..9761419b70 100644 --- a/OpenRA.Mods.Common/Widgets/ColorMixerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ColorMixerWidget.cs @@ -179,5 +179,11 @@ namespace OpenRA.Mods.Common.Widgets OnChange(); } } + + public override void Removed() + { + mixerSheet?.Dispose(); + base.Removed(); + } } } diff --git a/OpenRA.Mods.Common/Widgets/HueSliderWidget.cs b/OpenRA.Mods.Common/Widgets/HueSliderWidget.cs index ec711881db..2acde34da5 100644 --- a/OpenRA.Mods.Common/Widgets/HueSliderWidget.cs +++ b/OpenRA.Mods.Common/Widgets/HueSliderWidget.cs @@ -19,6 +19,7 @@ namespace OpenRA.Mods.Common.Widgets { Sprite hueSprite; Sprite pickerSprite; + Sheet hueSheet; public HueSliderWidget() { } public HueSliderWidget(HueSliderWidget other) @@ -28,7 +29,7 @@ namespace OpenRA.Mods.Common.Widgets { base.Initialize(args); - var hueSheet = new Sheet(SheetType.BGRA, new Size(256, 1)); + hueSheet = new Sheet(SheetType.BGRA, new Size(256, 1)); var buffer = new byte[4 * 256]; @@ -63,5 +64,11 @@ namespace OpenRA.Mods.Common.Widgets var pos = RenderOrigin + new int2(PxFromValue(Value).Clamp(0, rb.Width - 1) - (int)pickerSprite.Size.X / 2, (rb.Height - (int)pickerSprite.Size.Y) / 2); WidgetUtils.DrawSprite(pickerSprite, pos); } + + public override void Removed() + { + hueSheet?.Dispose(); + base.Removed(); + } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/EncyclopediaLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/EncyclopediaLogic.cs index eb4e9547ad..1cf1a95513 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/EncyclopediaLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/EncyclopediaLogic.cs @@ -50,6 +50,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly LabelWidget productionTime; readonly Widget productionPowerIcon; readonly LabelWidget productionPower; + readonly List sheets = new(); ActorInfo selectedActor; ScrollItemWidget firstItem; @@ -81,6 +82,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic defaultPortrait = new Png(modData.DefaultFileSystem.Open("encyclopedia/default.png")); var spriteBounds = new Rectangle(0, 0, defaultPortrait.Width, defaultPortrait.Height); var sheet = new Sheet(SheetType.BGRA, spriteBounds.Size.NextPowerOf2()); + sheets.Add(sheet); sheet.CreateBuffer(); sheet.GetTexture().ScaleFilter = TextureScaleFilter.Linear; portraitSprite = new Sprite(sheet, spriteBounds, TextureChannel.RGBA); @@ -304,5 +306,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic time = time * bi.BuildDurationModifier * pbi / 10000; return time; } + + protected override void Dispose(bool disposing) + { + foreach (var sheet in sheets) + sheet.Dispose(); + + base.Dispose(disposing); + } } } diff --git a/OpenRA.Mods.Common/Widgets/VideoPlayerWidget.cs b/OpenRA.Mods.Common/Widgets/VideoPlayerWidget.cs index dae1f05990..e43c6eb9af 100644 --- a/OpenRA.Mods.Common/Widgets/VideoPlayerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/VideoPlayerWidget.cs @@ -40,6 +40,7 @@ namespace OpenRA.Mods.Common.Widgets readonly Stopwatch playTime = new(); int textureWidth; int textureHeight; + Sheet videoSheet; Action onComplete; @@ -123,7 +124,8 @@ namespace OpenRA.Mods.Common.Widgets textureWidth = Exts.NextPowerOf2(video.Width); textureHeight = Exts.NextPowerOf2(video.Height); - var videoSheet = new Sheet(SheetType.BGRA, new Size(textureWidth, textureHeight)); + videoSheet?.Dispose(); + videoSheet = new Sheet(SheetType.BGRA, new Size(textureWidth, textureHeight)); videoSheet.GetTexture().ScaleFilter = TextureScaleFilter.Linear; videoSheet.GetTexture().SetData(video.CurrentFrameData, textureWidth, textureHeight); @@ -301,5 +303,11 @@ namespace OpenRA.Mods.Common.Widgets Stop(); Video = null; } + + public override void Removed() + { + videoSheet?.Dispose(); + overlaySheet?.Dispose(); + } } }