Home
Reply
Regular Contributor
jineshmac
Posts: 48

Adding pcurve to a coedge

Hi,

I tried adding a pcurve to a coedge by the following code:
_______________________________________________________
api_get_coedges(body, coedgList);
COEDGE * coedgg = (COEDGE*)coedgList[3];
sg_add_pcurve_to_coedge(coedgg, true);
const pcurve* pcr = &(coedgg->geometry()->equation());
SPAinterval pcrRange = pcr->param_range();
_______________________________________________________

But the last line of the code gives an exception saying:
"Unhandled exception at 0x02090ee1 (SpaACISd.dll)
0xC00000005: Access violation reading location 0xfeeeff42

I have attached the .sat file of the model.

Any suggestions regarding why this is failing will be highly appreciated.

Thanks,
Jinesh.

AR
Contributor
AR
Posts: 23

Re: Adding pcurve to a coedge

Documentation mentions that sg_add_pcurve_to_coedge will put a pcurve on coedge "if necessary".

Did you check if pcr != NULL?

 

AR

Regular Contributor
jineshmac
Posts: 48

Re: Adding pcurve to a coedge

Hello AR,

 

Yes I did check.  pcr is not NULL.

 

Thanks,

jinesh

Spatial Employee
asdf
Posts: 106

Re: Adding pcurve to a coedge

Hi Jinesh

 

I think the problem here is that you took the address of a temporary.  PCURVE::equation returns a pcurve by value, not the const& to a pcurve.  In the line where you assign pcurve const* pcur = &(coedge->geometry()->equation()) I think the destructor for the temprorary is being called before you access the pointer (c++ compilers are able to call the destructor as soon as they can prove a temporary is out of scope).

 

I tried the same thing in scheme and it worked, so I am reasonably confident that this is the problem.  The interface is wierd, especially given how CURVE::equation and SURFACE::equation return references rather than objects.  Part of the issue is that we don't really have first class pcurves (i.e., they are not polymorphic) so we don't need to pass back references.  I can't really come up with a better explanation for the wierdness of it than that.

 

hope this helps

 

Eric

Regular Contributor
Vi2
Posts: 72

Re: Adding pcurve to a coedge

Nice answer!

 

I have checked own sources and met code with this feature. As C++ programmers explained, C++ standard allow this.

PCURVE* pUVCurve = pCoEdge->geometry();
...
pcurve const & uvcurve = pUVCurve->equation();
...

 So TC can use a constant reference to temporary object instead of a pointer.

Regular Contributor
jineshmac
Posts: 48

Re: Adding pcurve to a coedge

Thanks Asdf and Vi2.

That solved my problem.

Regards,

Jinesh.