.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

"Unhandled Access Violation Reading" when using InsertVertexAt of Polyline3d

3 REPLIES 3
Reply
Message 1 of 4
dynamicscope
566 Views, 3 Replies

"Unhandled Access Violation Reading" when using InsertVertexAt of Polyline3d

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.

 

3 REPLIES 3
Message 2 of 4
fenton.webb
in reply to: dynamicscope

we need a sample project in order to see what's going on really... Also, which version of AutoCAD is this for?




Fenton Webb
AutoCAD Engineering
Autodesk

Message 3 of 4

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.

 

 

Message 4 of 4

Thank you for the good info. I will check with this. 😃

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost