diff --git a/OpenDreamClient/Rendering/DreamPlane.cs b/OpenDreamClient/Rendering/DreamPlane.cs index fe728efd69..1932e4d6c5 100644 --- a/OpenDreamClient/Rendering/DreamPlane.cs +++ b/OpenDreamClient/Rendering/DreamPlane.cs @@ -1,23 +1,17 @@ -using OpenDreamShared.Dream; -using Robust.Client.Graphics; +using Robust.Client.Graphics; using Robust.Shared.Utility; namespace OpenDreamClient.Rendering; -internal sealed class DreamPlane { - public IRenderTexture RenderTarget => _temporaryRenderTarget ?? _mainRenderTarget; +internal sealed class DreamPlane(IRenderTexture mainRenderTarget) : IDisposable { + public IRenderTexture RenderTarget => _temporaryRenderTarget ?? mainRenderTarget; public RendererMetaData? Master; public readonly List> IconDrawActions = new(); public readonly List> MouseMapDrawActions = new(); - private IRenderTexture _mainRenderTarget; private IRenderTexture? _temporaryRenderTarget; - public DreamPlane(IRenderTexture renderTarget) { - _mainRenderTarget = renderTarget; - } - public void Clear() { Master = null; IconDrawActions.Clear(); @@ -25,13 +19,18 @@ public void Clear() { _temporaryRenderTarget = null; } + public void Dispose() { + mainRenderTarget.Dispose(); + Clear(); + } + /// /// Sets this plane's main render target
/// Persists through calls to ///
public void SetMainRenderTarget(IRenderTexture renderTarget) { - _mainRenderTarget.Dispose(); - _mainRenderTarget = renderTarget; + mainRenderTarget.Dispose(); + mainRenderTarget = renderTarget; } /// @@ -47,9 +46,9 @@ public void SetTemporaryRenderTarget(IRenderTexture renderTarget) { /// public void Draw(DreamViewOverlay overlay, DrawingHandleWorld handle) { // Draw all icons - handle.RenderInRenderTarget(_mainRenderTarget, () => { + handle.RenderInRenderTarget(mainRenderTarget, () => { foreach (Action iconAction in IconDrawActions) - iconAction(_mainRenderTarget.Size); + iconAction(mainRenderTarget.Size); }, new Color()); if (_temporaryRenderTarget != null) { @@ -57,7 +56,7 @@ public void Draw(DreamViewOverlay overlay, DrawingHandleWorld handle) { handle.RenderInRenderTarget(_temporaryRenderTarget, () => { handle.UseShader(overlay.GetBlendAndColorShader(Master, useOverlayMode: true)); handle.SetTransform(overlay.CreateRenderTargetFlipMatrix(_temporaryRenderTarget.Size, Vector2.Zero)); - handle.DrawTextureRect(_mainRenderTarget.Texture, new Box2(Vector2.Zero, _mainRenderTarget.Size)); + handle.DrawTextureRect(mainRenderTarget.Texture, new Box2(Vector2.Zero, mainRenderTarget.Size)); handle.SetTransform(Matrix3.Identity); handle.UseShader(null); }, new Color()); diff --git a/OpenDreamClient/Rendering/DreamViewOverlay.cs b/OpenDreamClient/Rendering/DreamViewOverlay.cs index d26993c042..89ba23b6b6 100644 --- a/OpenDreamClient/Rendering/DreamViewOverlay.cs +++ b/OpenDreamClient/Rendering/DreamViewOverlay.cs @@ -608,7 +608,8 @@ private void ClearPlanes() { var plane = pair.Value; // We can remove the plane if there was nothing on it last frame - if (plane.IconDrawActions.Count == 0 && plane.MouseMapDrawActions.Count == 0) { + if (plane.IconDrawActions.Count == 0 && plane.MouseMapDrawActions.Count == 0 && plane.Master == null) { + plane.Dispose(); _planes.Remove(pair.Key); continue; } @@ -625,6 +626,7 @@ private DreamPlane GetPlane(int planeIndex, Vector2i viewportSize) { plane = new(renderTarget); _planes.Add(planeIndex, plane); + _sawmill.Info($"Created plane {planeIndex}"); return plane; }