You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a weird issue, as I wasn't able to reproduce it with a WASM Mono runtime or normal desktop application. But only with NativeAOT-LLVM.
It seems this issue is only reproducible after I replaced managed delegates with function pointers as part of #2615
But I decided to open this issue here instead, as it actually looks like a bug in SkiaSharp code, and exception is somehow swallowed outside of it.
Code
SkiaSharp has many methods accepting callbacks. Like:
public bool InstallPixels (SKImageInfo info, IntPtr pixels, int rowBytes, SKBitmapReleaseDelegate releaseProc, object context)
{
var cinfo = SKImageInfoNative.FromManaged (ref info);
var del = releaseProc != null && context != null
? new SKBitmapReleaseDelegate ((addr, _) => releaseProc (addr, context))
: releaseProc;
DelegateProxies.Create (del, out _, out var ctx);
return SkiaApi.sk_bitmap_install_pixels (Handle, &cinfo, (void*)pixels, (IntPtr)rowBytes, DelegateProxies.SKBitmapReleaseDelegateProxy, (void*)ctx);
}
The problem with this callback, that it passes proxy function to the DllImport even when releaseProc is null.
And from proxy implementation, it will always crash with NRE, as context is an empty pointer.
private static void SKSurfaceReleaseDelegateProxyImplementation (void* address, void* context)
{
var del = Get<SKSurfaceReleaseDelegate> ((IntPtr)context, out var gch);
try {
del.Invoke ((IntPtr)address, null);
} finally {
gch.Free ();
}
}
Expected Behavior
No exception.
Actual Behavior
Exception.
Version of SkiaSharp
3.x (Alpha)
Last Known Good Version of SkiaSharp
Other (Please indicate in the description)
IDE / Editor
Visual Studio (Windows)
Platform / Operating System
Other (Please indicate in the description)
Platform / Operating System Version
Reproduced on WASM (both Mono and NativeAOT)
_
Relevant Log Output
dotnet.native.js:1553 Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
maxkatz6
changed the title
[BUG] Null callback crash the app when used from delegate proxies (NativeAOT-LLVM only?)
[BUG] Delegate proxies crash with NRE when user delegate is null (only if rewrite to function pointers)
Jul 3, 2024
Description
This is a weird issue, as I wasn't able to reproduce it with a WASM Mono runtime or normal desktop application. But only with NativeAOT-LLVM.It seems this issue is only reproducible after I replaced managed delegates with function pointers as part of #2615
But I decided to open this issue here instead, as it actually looks like a bug in SkiaSharp code, and exception is somehow swallowed outside of it.
Code
SkiaSharp has many methods accepting callbacks. Like:
The problem with this callback, that it passes proxy function to the DllImport even when releaseProc is null.
And from proxy implementation, it will always crash with NRE, as
context
is an empty pointer.Expected Behavior
No exception.
Actual Behavior
Exception.
Version of SkiaSharp
3.x (Alpha)
Last Known Good Version of SkiaSharp
Other (Please indicate in the description)
IDE / Editor
Visual Studio (Windows)
Platform / Operating System
Other (Please indicate in the description)
Platform / Operating System Version
Reproduced on WASM (both Mono and NativeAOT)
_
Relevant Log Output
dotnet.native.js:1553 Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
Code of Conduct
The text was updated successfully, but these errors were encountered: