.NET

.NET

Reply
Valued Contributor
dynamicscope
Posts: 95
Registered: ‎04-04-2012
Message 1 of 4 (279 Views)

"Unhandled Access Violation Reading" when using InsertVertexAt of Polyline3d

279 Views, 3 Replies
04-08-2013 02:02 AM

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.

 

ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 2 of 4 (248 Views)

Re: "Unhandled Access Violation Reading" when using InsertVertexAt of

04-08-2013 03:11 PM 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

Developer Technical Services

Autodesk Developer Network


Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 3 of 4 (226 Views)

Re: "Unhandled Access Violation Reading" when using InsertVertexAt of

04-08-2013 08:05 PM in reply to: dynamicscope

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.

 

 

Valued Contributor
dynamicscope
Posts: 95
Registered: ‎04-04-2012
Message 4 of 4 (177 Views)

Re: "Unhandled Access Violation Reading" when using InsertVert

04-14-2013 05:34 PM in reply to: DiningPhilosopher
Thank you for the good info. I will check with this. =)
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.