Hi,
I am getting a wierd error.
I am getting "Unhandled Access Violation Reading" error when I use InsertVertexAt (of Polyline3d) and close AutoCAD.
This error happens when I CLOSE AutoCAD.
Here is my code snippet.
double param = pline3d.GetParameterAtPoint(points[0]); PolylineVertex3d prePv3d = null; foreach (PolylineVertex3d pv3d in pline3d) { double param2 = pline3d.GetParameterAtPoint(pv3d.Position); if (param2 > param) { if (prePv3d != null) { pline3d.InsertVertexAt(prePv3d, new PolylineVertex3d(points[0])); prePv3d.Dispose(); break; } } else { prePv3d = pv3d; } }
What could I use it wrong?
Any help would be appreciated.
Thank you in advance.
we need a sample project in order to see what's going on really... Also, which version of AutoCAD is this for?
Look at this line from your code:
pline3d.InsertVertexAt(prePv3d, new PolylineVertex3d(points[0]));
And then read this (From the ObjectARX Reference for InsertVertexAt()):
"If the polyline is database-resident then the inserted vertex must be explicitly closed by the calling application after the insertVertexAt() call returns. If the polyline is not database-resident, then there is no need to close the vertex since it hasn't been added to the database yet (calling close() on such a vertex will just result in close() returning Acad::eNoDatabase). "
Obviously, if you don't assign the new PolylineVertex3d to a variable before passing it to AddVertexAt(), then you can't be explicitly closing it, right?
You must either add the new PolylineVertex3d objects to the current transaction, or you must call their Close() method explicitly, after InsertVertexAt() returns.
You also should not need to call Dispose() on the existing PolylineVertex3d objects that you're iterating through.