I get randomly (on the live environment its like once every 2 weeks with a very active and hard working windows service, it resizes about 50000+ images per day) AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
The stacktrace is: Stack:
at WebSupergoo.ABCpdf7.Internal.NDoc._Clear(IntPtr inDoc)
at WebSupergoo.ABCpdf7.Internal.NDoc.Clear(IntPtr inDoc)
at WebSupergoo.ABCpdf7.Doc.Clear()
at WebSupergoo.ImageGlue7.Canvas.Dispose(Boolean disposing)
at WebSupergoo.ImageGlue7.Canvas.Dispose()
at XXXXX.Classes.Imaging.Image.Resize(Int32 width, Int32 height, Boolean addTransparent) in <path>\Image.cs:line 149
at XXXXX.Classes.XXXXX.Object.Import.Media.CreateImageScale(String destDir, Int32 width) in <path>\Media.cs:line 272
at XXXXX.Classes.XXXXX.Object.Import.Media.CreateResizedImages(String threadId) in <path>\Media.cs:line 242
at XXXXX.Classes.XXXXX.Object.Import.Threading.ResizeThread.Run(Object o) in <path>\ResizeThread.cs:line 38
Here is the code for the resize method:
public void Resize(int width, int height, bool addTransparent)
{
using (Canvas tempCanvas = new Canvas())
{
DrawOptions options = new DrawOptions();
if (height == 0)
{
if (width <= Width)
{
options.Limit = new Size(width, 0);
}
else
{
double scale = (double)width / (double)Width;
options.Transform.Magnify(scale, scale, 0, 0);
}
}
else if (width == 0)
{
if (height <= Height)
{
options.Limit = new Size(0, height);
}
else
{
double scale = (double)height / (double)Height;
options.Transform.Magnify(scale, scale, 0, 0);
}
}
else
{
double scaleX = (double)width / (double)Width;
double scaleY = (double)height / (double)Height;
options.Transform.Magnify(scaleX, scaleY, 0, 0);
}
//add transparency if set.
if (addTransparent)
options.Transparency = true;
tempCanvas.DrawImage(CurrentImage, options);
CurrentImage = tempCanvas.ToImage();
} <<<<---- HERE WE GET THE EXCEPTION ON THE DISPOSE
}
Can anyone help me solve why i get this error or if there is anything I can do about it.