The program exited with code-1073741819 (0xc0000005) 'Access violation'
<p>I'm using graphicPath to draw points and lines in the panel1. The code is as follows:</p>

<pre><code>private void panel1_Paint_1(object sender, PaintEventArgs e)
    {                 
        Graphics G = e.Graphics;
        GraphicsPath gp = new GraphicsPath();

        foreach (var line in tockeKoordinate)
        {
            gp.AddLine((float) (line.startX), (float) (line.startY), (float) (line.endX), (float) (line.endY));
            gp.CloseFigure();
        }
        var rect = gp.GetBounds();
        var scale = Math.Min(1f * (int)(panel1.ClientSize.Width) / rect.Width,
                               1f * (int)(panel1.ClientSize.Height) / rect.Height);          

        using (Pen pen = new Pen(Color.Black, 0.0001f))
                {
                    G.SmoothingMode = SmoothingMode.AntiAlias;
                    G.Clear(Color.White);
                    G.TranslateTransform(0, +panel1.ClientSize.Height);
                    G.ScaleTransform(scale, -scale);
                    G.TranslateTransform(-rect.X, -rect.Y);
                    G.DrawPath(pen, gp);
               }
        if(checkBox1.Checked)
        {
            gp.ClearMarkers();
            foreach (var line2 in tockeZelene)
            {
                gp.AddLine((float)(line2.startX), (float)(line2.startY), (float)(line2.endX), (float)(line2.endY));
                gp.CloseFigure();
            }

            using (pen2);
            {
                G.DrawPath(pen2, gp);   &lt;--- access violation here
            }  
        }      
    }
</code></pre>

<p>Basically i have two <code>Lists</code>: <code>Tockekoordinate</code> and <code>tockeZelena</code>. The first one contains all of the points, and the second one contains about 30% of the first one's points, which I want to paint green using my pen2 which is initialised at the beginning.</p>

<p>Assuming checkbox1 is checked, I run all the points in order to get the rectangle <code>GetBounds</code>, so I can scale the panel1 with the point coordinates.</p>

<p>Then the checkbox1.checked part comes and the application exits on the marked line.</p>

<p>Does anyone know what could cause this? Or at least know a way how to set up VS to show me more information about said error?</p>