diff --git a/Studio/CelesteStudio.WPF/SkiaDrawableHandler.cs b/Studio/CelesteStudio.WPF/SkiaDrawableHandler.cs index f35172c26..832de970e 100644 --- a/Studio/CelesteStudio.WPF/SkiaDrawableHandler.cs +++ b/Studio/CelesteStudio.WPF/SkiaDrawableHandler.cs @@ -34,10 +34,16 @@ protected override void OnRender(DrawingContext drawingContext) { } if (drawable.CanDraw) { - if (bitmap == null || surface == null || width != bitmap.PixelWidth || height != bitmap.PixelHeight) { + if (width != bitmap.PixelWidth || height != bitmap.PixelHeight) { + bitmap = null; + surface = null; + } + + if (bitmap == null) { const double bitmapDpi = 96.0; bitmap = new WriteableBitmap(width, height, bitmapDpi * dpiX, bitmapDpi * dpiY, PixelFormats.Pbgra32, null); - + } + if (surface == null) { surface?.Dispose(); surface = SKSurface.Create(new SKImageInfo(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul), bitmap.BackBuffer, bitmap.BackBufferStride, new SKSurfaceProperties(SKPixelGeometry.Unknown)); surface.Canvas.Scale((float)dpiX, (float)dpiY); @@ -55,12 +61,21 @@ protected override void OnRender(DrawingContext drawingContext) { canvas.Flush(); bitmap.AddDirtyRect(new Int32Rect(0, 0, width, height)); - if (DateTime.Now.Second % 10 > 5) { - bitmap.Invalidate(); - } bitmap.Unlock(); drawingContext.DrawImage(bitmap, new Rect(drawable.DrawX, drawable.DrawY, width / dpiX, height / dpiY)); + + if (DateTime.Now.Second % 15 > 10) { + bitmap = null; + System.Console.WriteLine("Bitmap clear"); + } else if (DateTime.Now.Second % 15 > 5) { + surface = null; + System.Console.WriteLine("Surface clear"); + } else { + bitmap = null; + surface = null; + System.Console.WriteLine("Bitmap surface clear"); + } } else { drawable.Invalidate(); }