如何捕获'FatalExecutionEngineError'在c#

本文关键字:FatalExecutionEngineError 何捕获 | 更新日期: 2023-09-27 18:04:34

我正在用c#例程试验一个我无法解决的乏味问题。我正在开发一个应用程序,该应用程序使用GDAL库(用c++编写的用于操作地理数据的DLL库)打开ESRI ShapeFile,并在PictureBox组件中显示地图。当我使用System.Drawing.Point对象的矢量来绘制多边形时,我得到以下消息:

管理调试助手'FatalExecutionEngineError'在'C:'Users'polli' IpeaGEO -git'IpeaGEO'bin'Debug'IpeaGEO.vshost.exe'中检测到一个问题。附加信息:运行时发现致命错误。错误地址是0x6ced9a0f,在线程0x1618中。错误码为0xc0000005

这是抛出异常的代码:

private void drawGeometry(Geometry geo, Graphics g, bool fill)
{
    // Some code here...
    // ...
    // Get the points count and the array to ask GDAL for coordinates.
    int count = geo.GetPointCount();
    double[] v = new double[2];
    Point[] polygon = new Point[count];
    for (int pid = 0; pid < count; pid++)
    {
        geo.GetPoint(pid, v);    // This is a call to GDAL (unmanaged) code.
        polygon[pid].X = getX((float)v[0]);
        polygon[pid].Y = getY((float)v[1]);
        // The Exception occurs just HERE!
        g.DrawPolygon(fgPen, polygon); // <--- EXCEPTION!!!
        if (fill) g.FillPolygon(fillBrush, polygon);
    }
    // Some code here...
    // ...
}

我有这个函数的另一个版本,工作得很好,我在不分配内存的情况下绘制每个线段:

private void drawGeometry(Geometry geo, Graphics g, bool fill)
{
    // Some code here...
    // ...
    Point start = new Point(), current = new Point(), previous = new Point();
    // Get the points count and the array to ask GDAL for coordinates.
    int count = geo.GetPointCount();
    double[] v = new double[2];
    for (int pid = 0; pid < count; pid++)
    {
        geo.GetPoint(pid, v);    // This is a call to GDAL (unmanaged) code.
        if (pid == 0)
        {
            start.X = previous.X = getX((float)v[0]);
            start.Y = previous.Y = getY((float)v[1]);
         } // if
         else
         {
             previous.X = current.X;
             previous.Y = current.Y;
         } // else
         current.X = getX((float)v[0]); current.Y = getY((float)v[1]);
         g.DrawLine(fgPen, previous.X, previous.Y, current.X, current.Y);
    } // for
    g.DrawLine(fgPen, start.X, start.Y, current.X, current.Y);
    // Some code here...
    // ...
}

我需要填充一些多边形,我不能用第二个版本的代码(这是工作良好)。使用try…catch不捕获异常。

我认为当垃圾收集器在后台运行时发生问题,我尝试访问多边形变量(即大约2000个元素的向量)。(这段代码在for语句中)。

有人知道如何捕获(或者,更好的是,避免)这种异常吗?

如何捕获'FatalExecutionEngineError'在c#

FatalExecutionEngineError在异常处理中是不可捕获的,它们通常是系统错误或封送错误,两者都不能在。net应用中处理。

相关文章:
  • 没有找到相关文章