Background: I use DirectX 9.0 managed libraries to convert arrays of 3D points to 2d screen coordinates. For speed, I use UnsafeNativeMethods to do all the transformations.
Problem: If my custom line trimming function is used, my application dies without any exceptions, it took me a while to realize that it is throwing a fatal System.ExecutionEngineException . I narrowed this down to happen due to 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 lineToClip then passed to UnsafeNativeMethod, which converts these vertices to 2d vertices. From everything that I see, when I go through it in debug mode, it works completely fine until it just dies.
I just can’t understand what’s wrong. Any help would be greatly appreciated.
c # exception managed-directx
tbridge
source share