Background:
I am using DirectX 9.0 Managed Libraries to transform arrays of 3d points to 2d screen coordinates. For speed I use the UnsafeNativeMethods to do all the transformations.
The Problem:
If my custom line clipping function is used my application dies without throwing any exceptions, it took me a while to figure out that it was throwing an uncatchable System.ExecutionEngineException
. I have narrowed it down to happening because of the last two lines of my clipping function.
List<Vector3> verticesAfterClipping = new List<Vector3>;
public unsafe void ClipLine(Line lineToClip)
{
this.verticesAfterClipping.Clear();
// Clipping algorithm happens here... (this is psuedo-code of what it does)
foreach(Vertex in lineToClip.Vertices)
{
bool thisIsClipped = // Set to whether this vertex is clipped
bool lastWasClipped = // Set to whether last vertex was clipped
if(thisIsClipped == false && lastWasClipped == true)
{
verticesAfterClipping.Add( /* intersection on clipping plane */ );
verticesAfterClipping.Add( /* thisVertex */ );
}
else if (thisIsClipped == false && lastWasClipped == false)
{
verticesAfterClipping.Add( /* thisVertex */ );
}
else if (thisIsClipped == true && lastWasClipped == false)
{
verticesAfterClipping.Add(/* intersection on clipping plane */);
}
}
// THIS IS WHERE BAD THINGS HAPPEN
lineToClip.Vertices = new Vertex[verticesAfterClipping.Count];
verticesAfterClipping.CopyTo(lineToClip.Vertices, 0);
}
When the verticesAfterClipping
list is copied to the lineToClip
vertices the lineToClip
object is then passed to an UnsafeNativeMethod which transforms these vertices to 2d vertices. From everything I can see when I step through it in Debug mode it is working completely fine, until it just dies.
I simply cannot figure out what is wrong. Any help would be much appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…