Reproducible Crash Using Graphics.DrawArc

Our software provides technical drawings. One particular drawing caused the application to crash each time with an OutOfMemoryException. During the investigation, nothing seemed ordinary; the application did not request a lot of memory, did not use a lot of pens. I tried to catch the exception and the application finished drawing without throwing another. In fact, there was always only one OutOfMemoryException, and it was always the same primitive graphic primitive.

The following code is the minimum required for this failure to occur. It seems that the exact combination of image size, pen style and coordinates causes an exception. Rounding the coordinates to three decimal places makes it disappear, as well as reduces the size of the graphics or uses a pen without a lighter.

using (Bitmap b = new Bitmap(200, 200))
{
  using (Graphics g = Graphics.FromImage(b))
  {
    using (Pen p = new Pen(Color.Black))
    {
      p.DashPattern = new float[]{10.0f, 2.0f};

      RectangleF r = new RectangleF(
        BitConverter.ToSingle(new byte[]{0xD3, 0x56, 0xB3, 0x42}, 0),
        BitConverter.ToSingle(new byte[]{0x87, 0x2D, 0x17, 0x43}, 0),
        BitConverter.ToSingle(new byte[]{0xE2, 0x81, 0xD1, 0x3F}, 0),
        BitConverter.ToSingle(new byte[]{0xE2, 0x81, 0xD1, 0x3F}, 0));
      float st = BitConverter.ToSingle(new byte[]{0x6B, 0xF6, 0x1A, 0x42}, 0);
      float sw = BitConverter.ToSingle(new byte[]{0x6D, 0x33, 0x4F, 0x40}, 0);

      g.DrawArc(p, r, st, sw);
    }
  }
}

In this case, it is not difficult to create a workaround, but I was wondering if anyone had an explanation for this.

+5
source share
1 answer

System.Drawing - GDI +, , .NET . C api, . GDI + 20 , . , doozy - Status:: GenericError. , , .

System.Drawing , , , . :: OutOfMemory . , , . , , OutOfMemoryException .NET.

. GDI + . , , . .

+4

All Articles