mono / SkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
MIT License
4.39k stars 535 forks source link

[BUG]I cannot draw a paint which has a custom SKSL shader, SEHException was thrown #2908

Open martinrhan opened 2 months ago

martinrhan commented 2 months ago

Description

I have a simple console application which create a bitmap and a canvas, then draw using a paint made from custom sksl shader. However, when canvas.DrawPaint(paint) is called, SEHException is thrown. The error code of is -2147467259, which is 0x80004005. In Common HRESULT Values, it's E_FAIL, Unspecified failure. I have no idea what's happening. The SkiaSharp version is 2.88.8. There's no last known version that make it work.

Code

Simply create a console application with top level statement and add package reference to SkiaSharp. In Program.cs write

using SkiaSharp;

string sksl = """
                    half4 main(float2 fragCoord) { 
                        return half4(0,0,0,1);
                    }
                    """;
string error;
SKRuntimeEffect runtimeEffect = SKRuntimeEffect.Create(sksl, out error);
SKShader shader = runtimeEffect.ToShader(true);
SKPaint paint = new SKPaint() {
    Shader = shader,
};

int width = 1024;
int height = 1024;

SKImageInfo imageInfo = new SKImageInfo(width, height, SKColorType.Rgba8888);
SKBitmap bitmap = new SKBitmap(imageInfo);
SKCanvas canvas = new SKCanvas(bitmap);
canvas.DrawPaint(paint); //SEHException thrown here

Expected Behavior

I should just draw fill the canvas by black color.

Actual Behavior

SEH exception with error code -2147467259 thrown.

Version of SkiaSharp

2.88.8

Last Known Good Version of SkiaSharp

N/A

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Windows

Platform / Operating System Version

Windows 11

Devices

No response

Relevant Screenshots

No response

Relevant Log Output

No response

Code of Conduct

nomi-san commented 2 months ago

Duplicate #2657, try upgrading your SkiaSharp to v3-preview.

    _effect = SKRuntimeEffect.CreateShader(src, out string error);
    _shader = _effect.ToShader();
    _paint = new SKPaint() { Shader = _shader };