Graphics.DrawPath throws System.OutOfMemoryException

Graphics.DrawPath throws System.OutOfMemoryException

Post by Raj Asha » Wed, 11 Jun 2003 10:03:17



Hi. I experience a System.OutOfMemoryException when I call DrawPath on a GraphicsPath object (name it OverallPath) which contains another, boundary-case GraphicsPath object (named LinePath), and a Pen object (named BluePen) with width greater than 1.5. LinePath contains a set of lines which my program separates (so that they don't appear to loop back to each other) by calling LinePath.StartFigure (or LinePath.CloseFigure) before the iterative generation of each line. Exception only occurs when LinePath contains more than one line, and when both endpoints of LinePath's last line coincide. I include below a C# code sample which replicates the exceptional case. You can run the code by creating a Windows Form project, and then copying this OnPaint() override into Form1.cs.

I appreciate any help, and any workarounds.

Thank you.

Raj

                Pen BluePen = new Pen(Color.Blue, 1.5001F);

                protected override void OnPaint( PaintEventArgs e )
                {
                        base.OnPaint(e);
                        GraphicsPath LinePath = new GraphicsPath();

                        //Crash also occurs with CloseFigure() call instead.
                        LinePath.StartFigure();

                        Point StartPoint = new Point(132, 184);
                        Point EndPoint = new Point(200, 32);
                        LinePath.AddLine(StartPoint, EndPoint);

                        LinePath.StartFigure();
                        LinePath.AddLine(34, 35, 34, 35);

                        //Crashing does not occur if single-point line somewhere in the GraphicsPath object's middle.
//                      LinePath.StartFigure();
//                      LinePath.AddLine(1, 2, 3, 4);

                        GraphicsPath OverallPath = new GraphicsPath();
                        OverallPath.AddPath(LinePath, true);

                        Graphics dc = e.Graphics;

                        //Crashes here.
                        dc.DrawPath(BluePen, OverallPath);
                }

 
 
 

Graphics.DrawPath throws System.OutOfMemoryException

Post by Raj Asha » Fri, 13 Jun 2003 02:35:31


Hi. I found a workaround. One can add the line formed between (-1, -1) and (-1, -2) to the end of LinePath before drawing. Incidentally, OverallPath is redundant in the below problem description. One only needs to call DrawPath() on LinePath in order to generate the exception.

Given the fix and that I could replicate the error in a sample, does this represent a possible bug in System.Drawing?

Raj

Quote:>-----Original Message-----
>Hi. I experience a System.OutOfMemoryException when I

call DrawPath on a GraphicsPath object (name it
OverallPath) which contains another, boundary-case
GraphicsPath object (named LinePath), and a Pen object
(named BluePen) with width greater than 1.5. LinePath
contains a set of lines which my program separates (so
that they don't appear to loop back to each other) by
calling LinePath.StartFigure (or LinePath.CloseFigure)
before the iterative generation of each line. Exception
only occurs when LinePath contains more than one line, and
when both endpoints of LinePath's last line coincide. I
include below a C# code sample which replicates the
exceptional case. You can run the code by creating a
Windows Form project, and then copying this OnPaint()
override into Form1.cs.
Quote:

>I appreciate any help, and any workarounds.

>Thank you.

>Raj

>            Pen BluePen = new Pen(Color.Blue, 1.5001F);

>            protected override void OnPaint( PaintEventArgs e )
>            {
>                    base.OnPaint(e);
>                    GraphicsPath LinePath = new GraphicsPath();

>                    //Crash also occurs with CloseFigure() call instead.
>                    LinePath.StartFigure();

>                    Point StartPoint = new Point(132, 184);
>                    Point EndPoint = new Point(200, 32);
>                    LinePath.AddLine(StartPoint, EndPoint);

>                    LinePath.StartFigure();
>                    LinePath.AddLine(34, 35, 34, 35);

>                    //Crashing does not occur if single-point line somewhere in the GraphicsPath object's middle.
>//                  LinePath.StartFigure();
>//                  LinePath.AddLine(1, 2, 3, 4);

>                    GraphicsPath OverallPath = new GraphicsPath();
>                    OverallPath.AddPath(LinePath, true);

>                    Graphics dc = e.Graphics;

>                    //Crashes here.
>                    dc.DrawPath(BluePen, OverallPath);
>            }
>.


 
 
 

1. Exception of type 'System.OutOfMemoryException' was thrown

I really REALLY hope that someone could help me.

I have to pass almost 400.000 records from a database to a textfile
Because of this amount the extension of the textfile is just something
I made up ...(.you_name_it)
I get an error while writing the data to the file at +/- 9000 records.
The error = Exception of type 'System.OutOfMemoryException' was thrown
And I don't know the solution :(

This is the peace of code I use for writing the records to the file.

         this.path_to_file =
         ConfigurationManager.AppSettings["ExportDir"] +
DateTime.Now.ToString(ConfigurationManager.AppSettings
["Export_FileName"]) + ConfigurationManager.AppSettings
["Export_Extension"];

         FileStream fm = new FileStream
            (this.path_to_file, FileMode.Create, FileAccess.ReadWrite,
FileShare.ReadWrite);

         StreamWriter sw = new StreamWriter(fm, Encoding.Default);

         List<Export> exportRecords = null;

         exportRecords = ExportList();
         try
         {
             int i = 0;
            foreach (Export ex in exportRecords)
            {
                sw.Write(ex.ExportLine());
               sw.Write(sw.NewLine);
               sw.Flush();
               exportlines += ex.ExportLine() + "\n";
                i++;
            }
         }
         catch (Exception exc)
         {
            Log.Write(exc.Message);
         }

2. Find opens in front of document being searched

3. Exception of type System.OutOfMemoryException is thrown

4. I would like to Know...

5. 'System.OutOfMemoryException' occurred in system.drawing.dll

6. Perflib Event Errors

7. OutOfMemoryException' thrown by OpenFileDialog

8. Netra X1 CD, RAM, disk

9. Creating big Strings throws OutOfMemoryException

10. System.InvalidCastException: An exception of type System.InvalidCastException was thrown.

11. Urgent: System.OutOfMemoryException Returning a DataSet

12. MDI Form 'System.OutOfMemoryException' error

13. Help!!!!!! System.OutOfMemoryException