question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Resize in parallel throws AccessViolationException or gives artifacts

See original GitHub issue

I’m getting some problems when I try to resize copies of an image multiple times in parallel. I’ve tried making a console application as simple as possible that demonstrates my issue:

class Program
{
    static void Main()
    {
        var originalFilepath = "C:\\original.png";
        var outputPath = "C:\\resized";
        Func<int, string> outputFilepath = i => $"{outputPath}\\{i}.png";
        var n = 1000;
        var width = 100;
        var height = 100;

        System.IO.Directory.CreateDirectory(outputPath);
        using (var originalImage = new MagickImage(originalFilepath))
        {
            var tasks = new List<Task>();
            for (int i=0;i<n;i++)
            {
                tasks.Add(ResizeAsync(originalImage, width, height, outputFilepath(i)));
            }

            Task.WhenAll(tasks).Wait();
        }
    }

    static async Task ResizeAsync(MagickImage originalImage, int width, int height, string outputFilepath)
    {
        await Task.Delay(1); 

        using (var resizeImage = new MagickImage(originalImage))
        {
            resizeImage.Resize(width, height);
            resizeImage.Write(outputFilepath);
        }
    }
}

If I run the above code using this image as original image: original I will either get an AccessViolationException or get a number of resized images with artifacts such as: 0 3 28 31

I’m using Visual Studio 2015 and Magick.NET-Q8-AnyCPU 7.0.7.300

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ExplicitlyImplicitcommented, Oct 10, 2017

Using build 7.0.7.700 still yields the same kind of artifacts (I tried the console application above).

1reaction
dlemstracommented, Oct 9, 2017

@ExplicitlyImplicit The new release was published yesterday, could you give it another try?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resizing images in parallel causing out of memory exception
Originally I was using Image.FromFile() but doing some research, I found that Image.FromStream() is the way to go. I think I have the ......
Read more >
Il2CppInspector Tutorial: Working with code in IL2CPP DLL ...
Many IL2CPP methods require some back-end thread structures to be set correctly or they will throw an access violation exception.
Read more >
https://raw.githubusercontent.com/dotnet/samples/m...
XPathObject<T> is throwing a FormatException when the value passed is ... Parallel Tests are Failing on AppVeyor Machines The following 5 tests are...
Read more >
Unity 2023.2.0b5
Fixed in 2023.2.0b7. Graphics Device Features: Rendering artifacts using Custom Render Texture shader on Sphere Game Object (UUM-43540).
Read more >
Vaa3D and Vaa3D-Neuron: help
I want to quantify the number of vessels in my 3D images. First I run the Neuron Tracing utility of Vaa3D, this gives...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found