Imagesharp: System.NullReferenceException when attempt to Mutate.Draw on a new created Image<L8>

Created on 10 Jun 2020  路  5Comments  路  Source: SixLabors/ImageSharp

Description

What i'm trying to do: Resize white pixels but keep original image Width & Height

Error: newImage=error CS0103: The name 'newImage' does not exist in the current context

image

void Resize() is called under a Task
this[layerIndex].Image; // Creates a new Image that loads compressed bytes in
Parallel Loop is executed once, every image instance are new objects created inside the loop (Not shared with other iterations)
Only line "newImage.Mutate(o => o.DrawImage(image, location, 1f));" can trigger the error, Resize operation always pass.

Collection is from 500 to 1000 images but i also tried with just one, same behaviour
This error don't always happens, if i keep redoing same operation sometimes it finish ok without error, others dont.

If i turn Parallel for into a normal for loop problem seens to never happen but of course way slower than using parallel which is what make me use Parallel instead.

System Configuration

  • ImageSharp version: 1.0.0-rc0002
  • Environment (Operating system, version and so on): Windows 10 v1909
  • .NET Framework version: .NET Standard 2.0 library, method called from .NET Framework 4.8 WinForm
bug

Most helpful comment

@sn4k3 Perfect. Yep, definitely the same issue. I've got #1234 waiting for review to fix this.

All 5 comments

@sn4k3 how is the compilation error CS0103 related to the rest of the issue?

Any chance you can create a self-contained console app repro? A lot may depend on image sizes, position of x,y and other contextual factors.

Repo here: https://github.com/sn4k3/PrusaSL1Viewer
How to reproduce: Execute Main app -> Menu -> Open -> sl1 file from zip. Go to Menu -> Mutators -> Resize -> Pick any value diferent from 100 -> Click ok -> Error happen here
Note the error doesn't always trigger but most of the times will

Void Resize(): https://github.com/sn4k3/PrusaSL1Viewer/blob/master/PrusaSL1Reader/FileFormat.cs#L636
Called at: https://github.com/sn4k3/PrusaSL1Viewer/blob/master/PrusaSL1Viewer/FrmMain.cs#L1893

input_file.zip

I think this might be related to #1230 @sn4k3 if you can provide a stack trace that would be really useful.

System.NullReferenceException
HResult=0x80004003
Message=A refer锚ncia de objecto n茫o foi definida como uma inst芒ncia de um objecto.
Source=mscorlib
StackTrace:
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at SixLabors.ImageSharp.GraphicOptionsDefaultsExtensions.GetGraphicsOptions(Configuration configuration)
at SixLabors.ImageSharp.GraphicOptionsDefaultsExtensions.GetGraphicsOptions(IImageProcessingContext context)
at SixLabors.ImageSharp.Processing.DrawImageExtensions.DrawImage(IImageProcessingContext source, Image image, Point location, Single opacity)
at UVtools.Parser.FileFormat.<>c__DisplayClass124_1.b__2(IImageProcessingContext o) in D:\Tiago\Dropbox\Programming\C#\UVtools\UVtools.Parser\FileFormat.cs:line 687

@sn4k3 Perfect. Yep, definitely the same issue. I've got #1234 waiting for review to fix this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jarroda picture jarroda  路  3Comments

vpenades picture vpenades  路  4Comments

xakep139 picture xakep139  路  4Comments

marcpabst picture marcpabst  路  3Comments

vad3x picture vad3x  路  4Comments