.NET

.NET

Reply
Valued Contributor
95 Posts
3 Kudos
Registered: ‎04-04-2012
Post 1 of 4

"Unhandled Access Violation Reading" when using InsertVertexAt of Polyline3d

309 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
352 Posts
27 Kudos
Registered: ‎07-24-2007
Post 2 of 4

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
370 Posts
175 Kudos
Registered: ‎05-06-2012
Post 3 of 4

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
95 Posts
3 Kudos
Registered: ‎04-04-2012
Post 4 of 4

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. =)
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!