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

Crash: adding vector3d into ResultBuffer.

11 REPLIES 11
Reply
Message 1 of 12
v1m2k3
1477 Views, 11 Replies

Crash: adding vector3d into ResultBuffer.

Hi,

I am trying to write a vector3d into entity extended data.

a crash is occurred in the following snippet.

...

...

Vector3d vec3d = new Vector3d(1,2,3);

aResultBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataXCoordinate , vec3d)); (Crash in this line.)

...

 

Crash Message:

System.NullReferenceExceptionObject reference not set to an instance of an object.
   at Autodesk.AutoCAD.DatabaseServices.ResultBuffer.TypedValueToResbuf(TypedValue value)
   at Autodesk.AutoCAD.DatabaseServices.ResultBuffer.Add(TypedValue value)
...

...

 

I tried changing DxfCodes, but no luck.

Could some one tell me where am I going wrong.

 

Regards,

Manoj Kumar V.

11 REPLIES 11
Message 2 of 12
chiefbraincloud
in reply to: v1m2k3

This is a pretty interesting one...

I thought it might be the DxfCode (from all my LSP experience I would have said that an arbitrary length 3D vector should be stored as 1012, which in my old LSP book says "A 3D World Space Displacement in XDATA".  The DxfCode enum name is ExtendedDataWorldXDisp.

 

I am storing quite a bit of entity Xdata, but none of it is Vectors, mostly Points and handles.  So I copied and tweaked one of my routines to store a vector, and no matter how I tried it it fatal errored AutoCAD.  (I didn't even get an exception message, even with a try/catch it never entered the catch)

 

Just for giggles, I tried storing the 3D vector values as a Point3d, using the Vector DxfCode, and it worked fine.  I have no idea why this would act this way.

 

Just to be thorough, I did make two assumptions about the code you did not post:

1.  aResultBuffer was declared as new or set to a reference.  if not the NullReferenceException would be expected.

2.  that you had already added the RegisteredApplicationName to your resbuf prior to the code you posted.

Dave O.                                                                  Sig-Logos32.png
Message 3 of 12
v1m2k3
in reply to: chiefbraincloud

In my post i made a mistake, instead of Extension dictionary i wrote as Extended data.

 

and i am sure ResultBuffer is initialized.

I even tried with 1012, but no luck.

 

so, you think should also try storing Vector3d as Point3d.

 

 

Message 4 of 12
chiefbraincloud
in reply to: v1m2k3

Since the required object for both Xdata and Extension Dictionaries is a ResultBuffer, and since the error is generated (by both my tests and yours) at the addition of the (TypedValue vector..) to the resbuf, I don't think that would make any difference.

 

"so, you think should also try storing Vector3d as Point3d."

 

The one thing I can say for sure is that when I tried it, the code succeeded, and I printed the data to the command line with a lisp routine, and the data was correct. 

 

What I did not try, was to read the data back out as a Vector3D in .NET.

 

If that fails, but reading it back out as a point3d works, you can always use point3d.GetAsVector to turn it back into a vector.  I'll try that part when I get back to work.

 

I'd love for someone from Autodesk to check this and confirm or deny that it is a bug, or that I am (we are) missing something.

 

Dave O.                                                                  Sig-Logos32.png
Message 5 of 12
chiefbraincloud
in reply to: v1m2k3

Well, It also fails with an Invalid Cast if you try to set the vector variable equal to the typedvalue.value retrieved from the resbuf, but retrieving it as a point3d worked, and you can set the vector =  point3d.GetAsVector, so unless someone else wants to chime in, that's what I would do.

Dave O.                                                                  Sig-Logos32.png
Message 6 of 12
Anonymous
in reply to: v1m2k3

I don't think you can add complex items to xdata,  you have to decompose them your self.

 

Add the items one at a time

 

such as

aResultBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataXCoordinate , vec3d.XValue));

aResultBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataYCoordinate , vec3d.YValue));

aResultBuffer.Add(new TypedValue((int)DxfCode.ExtendedDataZCoordinate , vec3d.Zvalue));

 

That should fix it

 

HomeBoy Out

Message 7 of 12
Anonymous
in reply to: v1m2k3

I know I am very late to the party, but still I came across the same problem and decided to put in my experience as well, also to indicate that the bug (?) persists till today:

 

...
Vector3d nv3d= new Vector3d(1.1, 2.2, 3.3);
...
int anint = 112;
TypedValue tv = new TypedValue(anint, nv3d);
ResultBuffer rb = new ResultBuffer(tv);      <- this is where I crash with the errors mentioned in the original post

 

I tried with various values for anint (as you see even with 112) but to no avail,

so now I am (too) going for the Point3d approach

Message 8 of 12
Alfred.NESWADBA
in reply to: Anonymous

Hi,

 

This code needs to be corrected:

    new ResultBuffer

...needs an array as parameter, not a single value, so you should use instead

    new ResultBuffer(new TypedValue() { tv })

 

HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 9 of 12
Anonymous
in reply to: Alfred.NESWADBA

Just tried it

 

 

...
Vector3d nv3d = new Vector3d(1.1, 2.2, 3.3);
...
int anint = 112; TypedValue tv = new TypedValue(anint, nv3d); ResultBuffer rb = new ResultBuffer(new TypedValue[] {tv} );

(also with anint = 10,11,110)

 

but still crashing

 

and I 'm sorry but I gave to disagree with you (although I saw that the documentation agrees with you)

because these:

 

...
Point3d np3d= new Point3d(1.1, 2.2, 3.3);
...
int anint = 10;
TypedValue tv = new TypedValue(anint, np3d);
ResultBuffer rb = new ResultBuffer(tv);
...
...
int ni = 25;
...
TypedValue tv = new TypedValue((int)DxfCode.Int32, ni);
ResultBuffer rb = new ResultBuffer(tv);

work just fine,

meaning that they are written into an Xrec going onto a line's Extension Dictionary.

checked it through Lisp on command prompt and with snoopdb

 

Message 10 of 12
_gile
in reply to: Anonymous

Hi,

 

First, the ResultBuffer type has an overloaded constructor which takes a (params TypedVaue[] values) argument.

The params keyword means the argument can be either void, one or more TypedValueS separated with commas or a TypedValeS array.

 

Second, as far as i know, there's none TypedValue.TypeCode for Vector3d type, neither in the DxfCode enum nor in the LispDataType one.

 

By my side, I always used as work around to use a Point3d instead of a Vector3d

 

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 11 of 12
Alfred.NESWADBA
in reply to: _gile

Hi,

 

thank you for correction, I should have tried it in VS (and should have looked to the function signature in detail) instead of just writing from remembering.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 12 of 12
Anonymous
in reply to: _gile

Firstly, thank you for your time.

 

As far as the TypeCode for Vector3d goes, I thought 111 would be appropriate because of these documents:

DXF Group Codes in Numerical Order Reference :

111

UCS X-axis (appears only if code 72 is set to 1)

DXF: X value; APP: 3D vector

 

and :

About DXF Formatting Conventions

 

which, as I understood them, 111 should apply to this context,

(althought that it is true that Vector3d doesn't exist in the mentioned enums)

but it obviously doesn't.

 

 

So thank you all for your time, Point3d it is

 

 

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