[SkiaSharp] AccessViolationException ์ฒ˜๋ฆฌ

Azure Function Service Bus Queue Trigger ํ™˜๊ฒฝ์—์„œ SkiaSharp์„ ์ด์šฉ ์ค‘์— AccessViolationException์ด ๋ฐœ์ƒํ–ˆ์—ˆ์Šต๋‹ˆ๋‹ค.

๊ด€๋ จํ•˜์—ฌ Github์— ์˜ฌ๋ ธ๋˜ ์งˆ๋ฌธ๊ณผ @evan-choi ๋‹˜๊ป˜์„œ ์ œ๊ณตํ•ด์ฃผ์‹  ํ•ด๊ฒฐ์ฑ…์„ ๊ณต์œ ํ•ฉ๋‹ˆ๋‹ค.

์˜ค๋ฅ˜ ๋ฐœ์ƒ

์˜ค๋ฅ˜ ํ•ด๊ฒฐ

SkiaSharp์„ ์‚ฌ์šฉํ•˜์‹œ๋Š” ๋ถ„๋“ค๊ป˜ ๋„์›€์ด ๋˜๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค.

5 Likes

์š”๊ฑฐ ๊ฐœ์ธ์ ์œผ๋กœ ๊ถ๊ธˆํ•œ ๋ถ€๋ถ„์ธ๋ฐ, ManagedStream ์‚ฌ์šฉ์ด ํ•ต์‹ฌ์ธ ๊ฑด๊ฐ€์š”โ€ฆ?

2 Likes

๊ทธ๋Ÿฐ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ €๋„ ์™œ ๊ทธ๋Ÿฐ์ง€๋Š” ํŒŒ์•…ํ•˜์ง€ ๋ชปํ–ˆ๊ณ  ์•Œ๋ ค์ฃผ์‹ ๋Œ€๋กœ ์ˆ˜ํ–‰ํ•œ ๋ถ€๋ถ„์ด๋ผโ€ฆ

๊ธฐ์–ต์€ ์ž˜ ์•ˆ๋‚˜์ง€๋งŒ ์–ด๋Š ๊ธ€์—์„ ๊ฐ€ SkManagedStream์€ ์“ฐ์ง€ ์•Š์•„๋„ ๋œ๋‹ค๊ณ  SkiaSharp ๊ฐœ๋ฐœ์ž๊ฐ€ ์ผ๋˜ ํฌ์ŠคํŠธ๋ฅผ ๋ดค๋˜ ๊ฒƒ ๊ฐ™์•„์„œ ๊ทธ๋™์•ˆ SkManagedStream ์—†์ด ์‚ฌ์šฉํ–ˆ์—ˆ๋Š”๋ฐ @evan-choi ๋‹˜๊ป˜์„œ ๋ง์”€ํ•ด์ฃผ์‹  ๊ฑดโ€ฆimagebytes ์Šคํƒ์ด ํ•ด์ œ๋˜๋ฉด์„œ unsafe memory์— ์˜ํ–ฅ์ด ์ƒ๊ธด ๊ฒƒ ๊ฐ™์œผ๋‹ˆ SkMangedStream์„ ์จ๋ณด๋ผ๊ณ  ํ•˜์…จ์Šต๋‹ˆ๋‹ค.

SKBitmap.Decode์—์„œ๋“œ ์ค‘์—์„œ ReadOnlySpan๋ฅผ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋ฐ›๋Š” ๋ฉ”์„œ๋“œ ์˜ค๋ฒ„๋กœ๋”ฉ์˜ ์ฝ”๋“œ์ •์˜๋ฅผ ์ฐพ์•„์„œ ๋ณด์—ฌ์ฃผ์…จ๋Š”๋ฐ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. Decode์ž์ฒด ์ฝ”๋“œ๊ฐ€ ์œ„ํ—˜ํ•˜๊ฒŒ ์ƒ๊ธฐ๊ธด ํ•˜์…จ๋‹ค๊ณ  ํ•˜์…”์„œ SKManagedStream์„ ์ถ”์ฒœํ•˜์…จ์Šต๋‹ˆ๋‹ค.

public static unsafe SKBitmap Decode(ReadOnlySpan<byte> buffer)
{
    fixed (byte* numPtr = &buffer.GetPinnableReference())
    {
        using (SKData data = SKData.Create((IntPtr) (void*) numPtr, buffer.Length))
        {
             using (SKCodec codec = SKCodec.Create(data))
             {
                  return SKBitmap.Decode(codec);
             }
        }
    }
}
2 Likes

์˜ค๋Š˜ SkiaSharp์— ๋Œ€ํ•ด ๋˜ AccessViolationException์ด ๋ฐœ์ƒํ–ˆ๊ณ , ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ข…๋ฃŒ๋˜๋Š” ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ์—ˆ์Šต๋‹ˆ๋‹ค.

SkBitmap.GetPixel(); ์„ ํ˜ธ์ถœํ•˜๋ฉด์„œ Skia ๋‚ด๋ถ€์˜ API๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๊ณผ์ •์—์„œ AccessViolationException์ด ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. ๋ฐ์ดํ„ฐ ์ž์ฒด๊ฐ€ ์ž˜๋ชป๋œ ๊ฒƒ์ด ๋“ค์–ด์™€์„œ ๋ฐœ์ƒํ•œ ์˜ค๋ฅ˜์˜€์ง€๋งŒ ํ”„๋กœ์„ธ์Šค๋Š” ์ข…๋ฃŒ๊ฐ€ ๋˜์ง€ ์•Š๊ณ  ๋Œ์•˜์–ด์•ผ ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ์•„๋ž˜ ๋ฐฉ๋ฒ•์—์„œ ๋„์›€์„ ๋ฐ›์•˜์Šต๋‹ˆ๋‹ค.

https://jacking.tistory.com/1411

@jacking75 ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!!

4 Likes

์˜ค๋ž˜์ „ ๊ธ€์ธ๋ฐ ๋„์›€ ๋˜์—ˆ๋‹ค๋‹ˆ ๋ฟŒ๋“ฏํ•ฉ๋‹ˆ๋‹ค^^
๊ณ ๋ง™์Šต๋‹ˆ๋‹ค~

4 Likes

๋จผ์ € ๋ฌธ์ œ ํ•ด๊ฒฐํ•œ ๋‚ด์šฉ์„ ๊ณต์œ ํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

๋™์ผํ•œ ์ด์Šˆ๋ฅผ ๊ฒช๋Š” ๋“ฏํ•˜์—ฌ ์ฐธ๊ณ ํ•˜๊ณ ์ž ํ•˜์˜€๋Š”๋ฐ, @jacking75 ๋‹˜ ๋ธ”๋กœ๊ทธ ๊ธ€ ๋งํฌ๊ฐ€ ์ ‘์†์ด ์•ˆ๋ฉ๋‹ˆ๋‹ค. :sob:
ํ˜น์‹œ ๋ธ”๋กœ๊ทธ๊ฐ€ ๋” ์ด์ƒ ์šด์˜๋˜์ง€ ์•Š๋Š” ๊ฑธ๊นŒ์š”?

2 Likes

ํ˜น์‹œ ํ‹ฐ์Šคํ† ๋ฆฌ ๋ธ”๋กœ๊ทธ๋ผ๋ฉด ํ‹ฐ์Šคํ† ๋ฆฌ๊ฐ€ ๋ธ”๋กœ๊ทธ๋ฅผ ์ •๋ฆฌํ•ด์„œ ๋‹ค ์‚ฌ๋ผ์กŒ์Šต๋‹ˆ๋‹ค ;;;
ํ˜„์žฌ๋Š” https://jacking75.github.io/ ์—ฌ๊ธฐ์— ๋ธ”๋กœ๊น… ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

4 Likes