I am experimenting a tedious problem with a C# routine that I cannot to solve. I am developing an application that opens a ESRI ShapeFile using the GDAL library (an DLL library written in C++ to manipulate geographical data) and shows the map in a PictureBox component. When I use a vector of System.Drawing.Point objects to draw the polygons I get the following message:
Managed Debugging Assistant 'FatalExecutionEngineError' has detected a problem in 'C:\\Users\\polli\\ipeageo-git\\IpeaGEO\\bin\\Debug\\IpeaGEO.vshost.exe'. Additional information: The runtime found a fatal error. The error address is 0x6ced9a0f, in thread 0x1618. The error code is 0xc0000005.
This is the code that throws the exception:
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...
// ...
}
I have another version of this function that works fine, where I am drawing each line segment without allocating memory:
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...
// ...
}
I need to fill some polygons and I cannot to do it with the second version of the code (that is working fine). The use of try ... catch does not capture the exception.
I think the problem occurs when the garbage collector is running in the background and I try to access the polygon variable (that is a vector of about 2000 elements... and this code is inside a for statement).
Anybody knows how to catch (or, even better, avoid) this kind of exception?
FatalExecutionEngineError在异常处理中无法捕获,它们通常是系统错误或编组错误,两者都无法在.NET应用程序中处理。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.