Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] System.AccessViolationException #2681

Open
1 task done
gktval opened this issue Dec 2, 2023 · 3 comments
Open
1 task done

[BUG] System.AccessViolationException #2681

gktval opened this issue Dec 2, 2023 · 3 comments
Labels

Comments

@gktval
Copy link

gktval commented Dec 2, 2023

Description

I am receiving an System.AccessViolationException error when subsetting, then resizing an image. It doesn't happen the first time, but if run it in a loop for several images, it will occur.

Anybody have an idea of a workaround for this issue in the mean time?

Code

SkBitmap bmp = <Load a bitmap of decent size>
var rect = new SKRectI(20, 20, 240, 240);
SKBitmap subset = new SKBitmap(rect.Width, rect.Height, SKImageInfo.PlatformColorType, SKAlphaType.Unpremul);
bmp.ExtractSubset(subset, rect);

int oBMPWidth = bmp.Width* 3;
int oBMPHeight = bmp.Height * 3;

// Scale the bitmap to the new size
SKBitmap ExtractedBitmap = subset.Resize(new SKImageInfo(oBMPWidth, oBMPHeight, SKImageInfo.PlatformColorType, SKAlphaType.Unpremul), SKFilterQuality.High);

Expected Behavior

No response

Actual Behavior

No response

Version of SkiaSharp

2.88.3 (Current)

Last Known Good Version of SkiaSharp

2.88.2 (Previous)

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

  • I agree to follow this project's Code of Conduct
@MateuszBogdan
Copy link

Probably duplicate of #2634 and #2645

@gktval
Copy link
Author

gktval commented Dec 4, 2023

It doesn't seem to matter which version of SkiaSharp I use. Nor does the error happen consistently. Seems to be more related to the previous issue I created #2456

@gktval
Copy link
Author

gktval commented Dec 4, 2023

As somewhat of a workaround I found if I manually dispose and garbage collect after resizing the image it will mostly fix the issue:

subset.Dispose();
subset = null;
GC.Collect();

I say mostly, because the error will not occur now after a few dozen iterations. Instead, I can process about a thousand images before I get an AccessViolation error. So perhaps there is another memory leak somewhere in another portion of the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants