diff --git a/src/Artemis.Core/Plugins/LayerBrushes/RgbNetLayerBrush.cs b/src/Artemis.Core/Plugins/LayerBrushes/RgbNetLayerBrush.cs index e52e06c13..843321c99 100644 --- a/src/Artemis.Core/Plugins/LayerBrushes/RgbNetLayerBrush.cs +++ b/src/Artemis.Core/Plugins/LayerBrushes/RgbNetLayerBrush.cs @@ -49,7 +49,7 @@ namespace Artemis.Core.LayerBrushes LedGroup.ZIndex = 1; List missingLeds = Layer.Leds.Where(l => !LedGroup.ContainsLed(l.RgbLed)).Select(l => l.RgbLed).ToList(); - List extraLeds = LedGroup.GetLeds().Where(l => Layer.Leds.All(layerLed => layerLed.RgbLed != l)).ToList(); + List extraLeds = LedGroup.Where(l => Layer.Leds.All(layerLed => layerLed.RgbLed != l)).ToList(); LedGroup.AddLeds(missingLeds); LedGroup.RemoveLeds(extraLeds); LedGroup.Brush = GetBrush(); @@ -78,7 +78,7 @@ namespace Artemis.Core.LayerBrushes throw new ArtemisCoreException("Cannot dispose RGB.NET layer brush because RgbService is not set"); Layer.RenderPropertiesUpdated -= LayerOnRenderPropertiesUpdated; - LedGroup?.Detach(RgbService.Surface); + LedGroup?.Detach(); LedGroup = null; } diff --git a/src/Artemis.Core/RGB.NET/SKTexture.cs b/src/Artemis.Core/RGB.NET/SKTexture.cs index 45d039203..59f8d0558 100644 --- a/src/Artemis.Core/RGB.NET/SKTexture.cs +++ b/src/Artemis.Core/RGB.NET/SKTexture.cs @@ -8,7 +8,7 @@ namespace Artemis.Core /// /// Represents a SkiaSharp-based RGB.NET PixelTexture /// - public sealed class SKTexture : PixelTexture + public sealed class SKTexture : PixelTexture, IDisposable { #region Constructors @@ -42,6 +42,12 @@ namespace Artemis.Core /// protected override ReadOnlySpan Data => Bitmap.GetPixelSpan(); + /// + public void Dispose() + { + Bitmap.Dispose(); + } + #endregion } } \ No newline at end of file diff --git a/src/Artemis.Core/Services/CoreService.cs b/src/Artemis.Core/Services/CoreService.cs index e4e0a460d..19b9b6210 100644 --- a/src/Artemis.Core/Services/CoreService.cs +++ b/src/Artemis.Core/Services/CoreService.cs @@ -258,10 +258,8 @@ namespace Artemis.Core.Services private void InvalidateBitmap() { - lock (_bitmapLock) { - _bitmap?.Dispose(); _bitmap = null; } } diff --git a/src/Artemis.Core/Services/DeviceService.cs b/src/Artemis.Core/Services/DeviceService.cs index 46f8bdc52..68329ac77 100644 --- a/src/Artemis.Core/Services/DeviceService.cs +++ b/src/Artemis.Core/Services/DeviceService.cs @@ -31,7 +31,7 @@ namespace Artemis.Core.Services Task.Run(async () => { await Task.Delay(200); - ledGroup.Detach(_rgbService.Surface); + ledGroup.Detach(); if (blinkCount < 5) { diff --git a/src/Artemis.Core/Services/RgbService.cs b/src/Artemis.Core/Services/RgbService.cs index f29cda2e9..30e359658 100644 --- a/src/Artemis.Core/Services/RgbService.cs +++ b/src/Artemis.Core/Services/RgbService.cs @@ -136,8 +136,11 @@ namespace Artemis.Core.Services public void UpdateTexture(SKBitmap bitmap) { + SKTexture? oldTexture = Texture; Texture = new SKTexture(bitmap); TextureBrush.Texture = Texture; + + oldTexture?.Dispose(); } private void SurfaceOnLayoutChanged(SurfaceLayoutChangedEventArgs args) => UpdateLedGroup(); @@ -161,7 +164,7 @@ namespace Artemis.Core.Services lock (_surfaceLedGroup) { // Clean up the old background - _surfaceLedGroup.Detach(Surface); + _surfaceLedGroup.Detach(); // Apply the application wide brush and decorator _surfaceLedGroup = new ListLedGroup(Surface, LedMap.Select(l => l.Key)) { Brush = TextureBrush }; diff --git a/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceDetectInputViewModel.cs b/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceDetectInputViewModel.cs index 4168c5b00..cd35e79f1 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceDetectInputViewModel.cs +++ b/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceDetectInputViewModel.cs @@ -43,7 +43,7 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs { base.OnDialogClosed(sender, e); _inputService.DeviceIdentified -= InputServiceOnDeviceIdentified; - _ledGroup.Detach(_rgbService.Surface); + _ledGroup.Detach(); } private void InputServiceOnDeviceIdentified(object sender, EventArgs e)