I am currently working on a Proof Of Concept project with SkiaSharp. I am very happy with the library, especially that you can use the powerful Skia library with C#. Unfortunately I now get an unhandle exception when using snapshots (mouse move). For the final goal I need a canvas of 8000x2000 pixels. When the canvas is smaller (300x400) the exception is not occuring. I hope someone knows what causes it. It could also be that I don't really understand the concept yet.
Also try to use SaveLayer but was not working as expected!
Purpose Want to implement a Drag and drop function with SkiaSharp.
When the mouse moves, a snapshot is taken; then draw what has changed. When the OnPaintSurface has been called 80 times or so, the exception occurs.
Expectations
No exception
propose a different approach so that the Exception no longer occurs
It may also be that there is a bug in the SkiaSharp;SkiaSharp.Views.Blazor library
private void OnPaintSurface(SKPaintSurfaceEventArgs e)
{
var canvas = e.Surface.Canvas; // 8000x2000
SKRect rect1 = new SKRect(0, 0, e.Info.Rect.Width, e.Info.Rect.Height);
if (firstRun)
{
DrawBackground(e);
layerBackGround = e.Surface.Snapshot();
firstRun = false;
}
else
{
canvas.DrawImage(layerBackGround, rect1);
// Draw something permanent
layerBackGround = e.Surface.Snapshot(); // Here the exception is raised
// Draw something temporary
using (SKPaint paint = new SKPaint { Style = SKPaintStyle.Stroke, Color = SKColors.Red })
{
canvas.DrawCircle(mouseLocation, 100, paint);
}
Console.WriteLine($"Restore Snapshot Number Restore {counterSnapshots++}");
}
}
private void OnMouseMove(MouseEventArgs e)
{
mouseLocation = new SKPoint((float)e.OffsetX, (float)e.OffsetY);
skiaView.Invalidate();
}
> Uncaught Error 63124824
at ___cxa_throw (localhost꞉7040/_framework/dotnet.7.0.12.y6rpn8jldv.js:1897:7)
at $operator new(unsigned long) (wasm/05035f22:1:7760148)
at $SkData::PrivateNewWithCopy(void const*, unsigned long) (wasm/05035f22:1:253631)
at $SkData::MakeWithCopy(void const*, unsigned long) (wasm/05035f22:1:253980)
at $MakeRasterCopyPriv(SkPixmap const&, unsigned int) (wasm/05035f22:1:3344311)
at $SkMakeImageFromRasterBitmapPriv(SkBitmap const&, SkCopyPixelsMode, unsigned int) (wasm/05035f22:1:3345209)
at $SkMakeImageFromRasterBitmap(SkBitmap const&, SkCopyPixelsMode) (wasm/05035f22:1:3345552)
at $SkSurface_Raster::onNewImageSnapshot(SkIRect const*) (wasm/05035f22:1:3347489)
at $SkSurface::makeImageSnapshot() (wasm/05035f22:1:3351341)
at $sk_surface_new_image_snapshot (wasm/05035f22:1:5273126)
at $do_icall (wasm/05035f22:1:5366088)
at $do_icall_wrapper (wasm/05035f22:1:5361988)
at $interp_exec_method (wasm/05035f22:1:5299397)
at $interp_runtime_invoke (wasm/05035f22:1:5294797)
at $mono_jit_runtime_invoke (wasm/05035f22:1:7352181)
at $do_runtime_invoke (wasm/05035f22:1:5907916)
at $mono_runtime_invoke_checked (wasm/05035f22:1:5907796)
at $mono_runtime_try_invoke_span (wasm/05035f22:1:5927157)
at $mono_runtime_invoke_span_checked (wasm/05035f22:1:5927774)
at $ves_icall_InternalInvoke (wasm/05035f22:1:5729477)
at $ves_icall_InternalInvoke_raw (wasm/05035f22:1:5759520)
at $do_icall (wasm/05035f22:1:5366277)
at $do_icall_wrapper (wasm/05035f22:1:5361988)
at $interp_exec_method (wasm/05035f22:1:5299397)
at $interp_runtime_invoke (wasm/05035f22:1:5294797)
at $mono_jit_runtime_invoke (wasm/05035f22:1:7352181)
at $do_runtime_invoke (wasm/05035f22:1:5907916)
at $mono_runtime_try_invoke (wasm/05035f22:1:5909851)
at $mono_runtime_invoke (wasm/05035f22:1:5918698)
at $mono_wasm_invoke_method_ref (wasm/05035f22:1:7777494)
at Module._mono_wasm_invoke_method_ref (localhost꞉7040/_framework/dotnet.7.0.12.y6rpn8jldv.js:8654:129)
at _Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_InvokeDotNet (dotnet.generated.invalid/_Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_InvokeDotNet:29:5)
at invokeDotNetFromJS (localhost꞉7040/_framework/blazor.webassembly.js:1:45224)
at g (localhost꞉7040/_framework/blazor.webassembly.js:1:1621)
at invokeMethod (localhost꞉7040/_framework/blazor.webassembly.js:1:3812)
at <anonymous> (C:\Users\r.gombert\.nuget\packages\skiasharp.views.blazor\2.88.6\staticwebassets\SKHtmlCanvas.js:104:38)
--- requestAnimationFrame ---
at requestAnimationFrame (C:\Users\r.gombert\.nuget\packages\skiasharp.views.blazor\2.88.6\staticwebassets\SKHtmlCanvas.js:98:41)
at requestAnimationFrame (C:\Users\r.gombert\.nuget\packages\skiasharp.views.blazor\2.88.6\staticwebassets\SKHtmlCanvas.js:68:33)
at invokeJSFromDotNet (localhost꞉7040/_framework/blazor.webassembly.js:1:3219)
at Gt (localhost꞉7040/_framework/blazor.webassembly.js:1:62634)
at Ii (localhost꞉7040/_framework/dotnet.7.0.12.y6rpn8jldv.js:5:71974)
at _mono_wasm_invoke_js_blazor (localhost꞉7040/_framework/dotnet.7.0.12.y6rpn8jldv.js:7677:71)
at $do_icall (wasm/05035f22:1:5366372)
at $do_icall_wrapper (wasm/05035f22:1:5361988)
at $interp_exec_method (wasm/05035f22:1:5299397)
at $interp_runtime_invoke (wasm/05035f22:1:5294797)
at $mono_jit_runtime_invoke (wasm/05035f22:1:7352181)
at $do_runtime_invoke (wasm/05035f22:1:5907916)
at $mono_runtime_invoke_checked (wasm/05035f22:1:5907796)
at $mono_runtime_try_invoke_span (wasm/05035f22:1:5927157)
at $mono_runtime_invoke_span_checked (wasm/05035f22:1:5927774)
at $ves_icall_InternalInvoke (wasm/05035f22:1:5729477)
at $ves_icall_InternalInvoke_raw (wasm/05035f22:1:5759520)
at $do_icall (wasm/05035f22:1:5366277)
at $do_icall_wrapper (wasm/05035f22:1:5361988)
at $interp_exec_method (wasm/05035f22:1:5299397)
at $interp_runtime_invoke (wasm/05035f22:1:5294797)
at $mono_jit_runtime_invoke (wasm/05035f22:1:7352181)
at $do_runtime_invoke (wasm/05035f22:1:5907916)
at $mono_runtime_invoke_checked (wasm/05035f22:1:5907796)
at $mono_runtime_try_invoke_span (wasm/05035f22:1:5927157)
at $mono_runtime_invoke_span_checked (wasm/05035f22:1:5927774)
at $ves_icall_InternalInvoke (wasm/05035f22:1:5729477)
at $ves_icall_InternalInvoke_raw (wasm/05035f22:1:5759520)
at $do_icall (wasm/05035f22:1:5366277)
at $do_icall_wrapper (wasm/05035f22:1:5361988)
at $interp_exec_method (wasm/05035f22:1:5299397)
at $interp_runtime_invoke (wasm/05035f22:1:5294797)
at $mono_jit_runtime_invoke (wasm/05035f22:1:7352181)
at $do_runtime_invoke (wasm/05035f22:1:5907916)
at $mono_runtime_try_invoke (wasm/05035f22:1:5909851)
at $mono_runtime_invoke (wasm/05035f22:1:5918698)
at $mono_wasm_invoke_method_ref (wasm/05035f22:1:7777494)
at Module._mono_wasm_invoke_method_ref (localhost꞉7040/_framework/dotnet.7.0.12.y6rpn8jldv.js:8654:129)
at _Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_BeginInvokeDotNet (dotnet.generated.invalid/_Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_BeginInvokeDotNet:29:5)
at beginInvokeDotNetFromJS (localhost꞉7040/_framework/blazor.webassembly.js:1:45087)
at b (localhost꞉7040/_framework/blazor.webassembly.js:1:1998)
at invokeMethodAsync (localhost꞉7040/_framework/blazor.webassembly.js:1:3866)
at <anonymous> (localhost꞉7040/_framework/blazor.webassembly.js:1:11414)
at invokeWhenHeapUnlocked (localhost꞉7040/_framework/blazor.webassembly.js:1:47333)
at S (localhost꞉7040/_framework/blazor.webassembly.js:1:58698)
at A (localhost꞉7040/_framework/blazor.webassembly.js:1:11383)
at dispatchGlobalEventToAllElements (localhost꞉7040/_framework/blazor.webassembly.js:1:13968)
at onGlobalEvent (localhost꞉7040/_framework/blazor.webassembly.js:1:13161)
The thread '[Thread Destroyed]' (0x9c38) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (0x6960) has exited with code 0 (0x0).
The thread '[Thread Destroyed]' (0x18f4) has exited with code 0 (0x0).
The thread 0x880 has exited with code 0 (0x0).
`