Skip to content

Commit

Permalink
fix(Studio): Zero-sized SkiaSharp canvas on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
psyGamer committed Feb 12, 2025
1 parent d3d7fde commit ea1c070
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions Studio/CelesteStudio.Mac/SkiaDrawableHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,28 @@ public override void DrawRect(CGRect dirtyRect) {
// Allocate a memory for the drawing process
nuint infoLength = (nuint)info.BytesSize;
if (surface == null || bitmapData?.Length != infoLength) {
dataProvider?.Dispose();
bitmapData?.Dispose();

bitmapData = NSMutableData.FromLength(infoLength);
dataProvider = new CGDataProvider(bitmapData.MutableBytes, info.BytesSize);

surface?.Dispose();
surface = SKSurface.Create(info, bitmapData.MutableBytes, info.RowBytes);
surface.Canvas.Scale((float)scale);
surface.Canvas.Save();
if ((int) bounds.Width == 0 || (int) bounds.Height == 0) {
// A zero sized surface causes issues, so use a null 1x1
// drawable.Draw() still needs to be called, so simply skipping render is not an option
dataProvider?.Dispose();
dataProvider = null;
bitmapData?.Dispose();
bitmapData = null;

surface?.Dispose();
surface = SKSurface.CreateNull(1, 1);
} else {
dataProvider?.Dispose();
bitmapData?.Dispose();

bitmapData = NSMutableData.FromLength(infoLength);
dataProvider = new CGDataProvider(bitmapData.MutableBytes, info.BytesSize);

surface?.Dispose();
surface = SKSurface.Create(info, bitmapData.MutableBytes, info.RowBytes);
surface.Canvas.Scale((float)scale);
surface.Canvas.Save();
}
}

var canvas = surface.Canvas;
Expand Down

0 comments on commit ea1c070

Please sign in to comment.