-
-
Notifications
You must be signed in to change notification settings - Fork 840
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
Fatal error. System.AccessViolationException When Encode #2595
Comments
We’ll need an input image that triggers the crash. This is very odd code btw? Why are you creating that |
This error does not appear in the same picture, but occurs randomly in tens of thousands of pictures. |
@br3aker I'm a little confused following this code so will need your assistance diagnosing if I can? I'm assuming the unused property @wuyu8512 Are you operating on If you need direct pixel access for your operations. This is the best and secure way. image.ProcessPixelRows(accessor =>
{
for (int y = 0; y < accessor.Height; y++)
{
Span<Bgra32> row = accessor.GetRowSpan(y);
Span<byte> byteRow = MemoryMarshal.Cast<Bgra32, byte>(row);
// Manipulate the row bytes directly.
}
}); |
i was operating on
I hope to be compatible with both ImageSharp and SkiaSharp, so getting all the data and processing it will make it easier for me to write a universal library
Yes, I updated all the code Assuming that the object of the Save method is changed to |
Save doesn't mutate the image. It only encodes it. I can't see where
You should create a 2D buffer abstraction that allows per-row access instead of using the array for your custom methods. That would be the only type you implement for both ImageSharp and SkiaSharp. |
Sorry, my express was not good, I modify my express again
Yes, the pixels buffer will never set
i will try |
After forcing the use of Webp, the problem no longer occurs
|
I suspect that If so, please let me know and also let me know the dimension range of the images you are using? |
if use Since this issue only occurs in my production environment, I'm sorry I can't always test it |
Is this sample (but using the jpeg encoder) enough to trigger the issue? |
yes |
Isn't it the ImageSharp/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs Lines 200 to 211 in 0d1296f
I need to refresh my memory about the SIMD packing/unpacking algorithms, but I would think this could be a more likely case, assuming a83b3b6 from #2120 implemented the mirror operation of #1462. In this case ImageSharp/src/ImageSharp/Formats/Jpeg/Components/Encoder/SpectralConverter{TPixel}.cs Line 114 in 0d1296f
This is how it's done in the decoder: ImageSharp/src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs Lines 155 to 167 in 0d1296f
|
I can repro this without Configuration.Default.MemoryAllocator = new SimpleGcMemoryAllocator();
Parallel.For(0, 10_000, i =>
{
using Image<Bgra32> image = new Image<Bgra32>(Random.Shared.Next(3000) + 1, Random.Shared.Next(3000) + 1);
using MemoryStream stream = new MemoryStream();
image.SaveAsJpeg(stream);
}); |
This can be further reduced to Configuration configuration = Configuration.CreateDefaultInstance();
configuration.MemoryAllocator = new SimpleGcMemoryAllocator();
using Image<Bgra32> image = new(configuration, 132, 1606);
using MemoryStream stream = new();
image.SaveAsJpeg(stream); |
Prerequisites
DEBUG
andRELEASE
modeImageSharp version
3.0.2
Other ImageSharp packages and versions
No
Environment (Operating system, version and so on)
Ubuntu 22.04.3 LTS
.NET Framework version
.Net 8
Description
Steps to Reproduce
Sorry for my bad English,
When big number of requests(about avg 2request/1s), an error will throw, But I can't reproduce it on my local computer
Images
No response
The text was updated successfully, but these errors were encountered: