From 37a1a5553de73c48c80b61347f7273641d4a6891 Mon Sep 17 00:00:00 2001 From: Lobster Uberlord Date: Mon, 4 Jul 2022 19:16:25 +0700 Subject: [PATCH] Use Marshal.AllocHGlobal to allocate frame buffer --- src/Web/Avalonia.Web.Blazor/BlazorSkiaRasterSurface.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Web/Avalonia.Web.Blazor/BlazorSkiaRasterSurface.cs b/src/Web/Avalonia.Web.Blazor/BlazorSkiaRasterSurface.cs index a286affe04..603a792de3 100644 --- a/src/Web/Avalonia.Web.Blazor/BlazorSkiaRasterSurface.cs +++ b/src/Web/Avalonia.Web.Blazor/BlazorSkiaRasterSurface.cs @@ -65,26 +65,22 @@ namespace Avalonia.Web.Blazor private readonly struct FramebufferData { - private readonly byte[]? _data; - private readonly GCHandle _dataHandle; - public PixelSize Size { get; } public int RowBytes { get; } - public IntPtr Address => _dataHandle.AddrOfPinnedObject(); + public IntPtr Address { get; } public FramebufferData(int width, int height, int bytesPerPixel) { Size = new PixelSize(width, height); RowBytes = width * bytesPerPixel; - _data = new byte[width * height * bytesPerPixel]; - _dataHandle = GCHandle.Alloc(_data, GCHandleType.Pinned); + Address = Marshal.AllocHGlobal(width * height * bytesPerPixel); } public void Dispose() { - _dataHandle.Free(); + Marshal.FreeHGlobal(Address); } } }