StackOverflowException

Jan 27, 2015 at 8:04 AM
Hello, great product, thanks for it. I had to develop c# application using MagickImage. Application shows picture in winforms picturebox. Also there is a listbox in a form with images fileinfos, holded in current folder. All images are the same type, tipycally b/w 16bpp pgm. The images are quit small - 300-800px square and were captured by a b/w video camera.
The common situation is when there are thowsands of images in the list. Choosing the next file in list changes the image in picturebox. So, if I press and hold keyboard arrow button, the image in list and picturebox image changes very quickly, like in a movie. When hundreds of images are passed, MagickImage crashes with StackOverflowException. If I list some images and pause for a little, everythig works fine.
Any try catch blocks don't help. You can see this behavior in my application PGMania http://sourceforge.net/projects/pgmania/

Test files can be downloaded here https://yadi.sk/d/mjuOEKr4eGE69

A piece of code I used:

private void ShowImageFile(string fileName)
    {
            byte[] data = File.ReadAllBytes(fileName);
            using (MagickImage image = new MagickImage(data))
            {
                ColorSpace originalColorSpace = image.ColorSpace;
                format = originalColorSpace.ToString();
                bitDepth = image.BitDepth();
                pictureBox.Image = null;
                GC.Collect();     
                try
                {
                    panel1.AutoScroll = false;
                    pictureBox.Dock = DockStyle.Fill;
                    pictureBox.SizeMode = PictureBoxSizeMode.Zoom;

                    Bitmap bm = new Bitmap(image.ToBitmap());
                    pictureBox.Image = bm;

                    pictureBox.Height = pictureBox.Image.Height;
                    pictureBox.Width = pictureBox.Image.Width;

                    ColorSpace transformedColorSpace = image.ColorSpace;

                    double windowZoom = (double)pictureBox.Width / image.Width;
                    windowZoom = Math.Round(windowZoom * 100, 0);
                    GC.AddMemoryPressure(data.Length);
                }
                catch
                {
                }
            }
    }
Coordinator
Jan 27, 2015 at 10:55 AM
I am sorry but I won't run an executable from an unknown source. You did not publish any source code so i cannot build it myself.

Can you reproduce the problem with the latest version of Magick.NET? Can you post the stacktrace somewhere if it still fails so I can determine which method is causing the problem.
Jan 28, 2015 at 6:15 AM

Hello,

Yes, I had downloaded the last version and there are the same things. The code where the Magick.NET used I showed in message. I can't show the whole project, sorry. Stack was is impossible to get with this exception.

Eugene

27.01.2015, 13:55:06 пользователь dlemstra ([email removed]) написал:


From: dlemstra

I am sorry but I won't run an executable from an unknown source. You did not publish any source code so i cannot build it myself.

Can you reproduce the problem with the latest version of Magick.NET? Can you post the stacktrace somewhere if it still fails so I can determine which method is causing the problem.

Read the full discussion online.

To add a post to this discussion, reply to this email ([email removed])

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com

Coordinator
Jan 28, 2015 at 10:50 AM
Coordinator
Jan 28, 2015 at 11:18 AM
Edited Jan 28, 2015 at 11:19 AM
Can you stop spamming the discussion board with a Russian text that contains a link to your site?
Jan 28, 2015 at 11:48 AM
Coordinator
Jan 28, 2015 at 6:32 PM
I cannot get any information from your dump. Is it possible that there is a memory issue? You are doing the following:
Bitmap bm = new Bitmap(image.ToBitmap());
pictureBox.Image = bm;
This creates a copy of the bitmap and you are not disposing the other image. Can you change it to this:
Bitmap bm = pictureBox.Image;
pictureBox.Image = image.ToBitmap();
if (bm != null)
  bm.Dispose();
Jan 28, 2015 at 8:15 PM
this code
Bitmap bm = (Bitmap )pictureBox.Image;
pictureBox.Image = image.ToBitmap();
if (bm != null)
  bm.Dispose();
does not helps.

What do you mean under "Is it possible that there is a memory issue?" . The process uses 35mb before and 87 mb after it crush.

"This creates a copy of the bitmap and you are not disposing the other image.'

Bitmap bm = new Bitmap(image.ToBitmap());
pictureBox.Image = bm;

it is equal to

pictureBox.Image = new Bitmap(image.ToBitmap());

If I dispose bm, the pictureBox will be clear. I do

pictureBox.Image = null;
GC.Collect();

before this to dispose the previous image.
Coordinator
Jan 28, 2015 at 9:10 PM
I assumed new Bitmap(image.ToBitmap()); would create a copy of the image, it looks like a copy constructor.

I was thinking it might be a memory issue because the dump does not tell me where it crashes. Can you switch to MagickNET-x86 and create a dump from there to see if that helps?