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

AcDbFullSubentPathArray::remove changes const parameter

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
khunstad
492 Views, 4 Replies

AcDbFullSubentPathArray::remove changes const parameter

I am trying to override subUnhighlight in a custom object consisting of lot of subentities. Which is really hard, because the ObjectArx documentation isn't exactly extensive around this. Right now I'm having trouble with what seems to be a function changing the contents of a const parameter. Look at this:

 

Acad::ErrorStatus CvWSPolyline::subUnhighlight(const AcDbFullSubentPath& subId /* = kNullSubent */, const Adesk::Boolean highlightAll /* = false */) const
{
  // AcDbFullSubentPathArray& highlightedSubents is a global array defined elsewhere, keeping track of which objects are highlighted

  static int callNr = 0;
  ++callNr;
  const int gsMarker = (int) subId.subentId().index();
  REL_DBGOUT(_T("\n%04d subentId: %d, gsMarker %d"), callNr, (int) subId.subentId().index(), gsMarker);
  if (subId.subentId().index() > 0)
  {
    if (highlightedSubents.contains(subId))
    {
      REL_DBGOUT(_T("\n%04d subentId %d"), callNr, (int) subId.subentId().index());
      highlightedSubents.remove(subId);
      REL_DBGOUT(_T("\n%04d subentId %d removed from highlightedSubents, new length %d, gsMarker %d"), callNr, (int) subId.subentId().index(), highlightedSubents.length(), gsMarker);
...

 which gives the following debug output:

 

0004 wsModelId: 40, gsMarker 40
0004 subId 40
0004 subId 30 removed from highlightedSubents, new length 2, gsMarker 40

 where the value of subId.subentId().index() has changed after the remove call (happen's only if there are more than 1 item in the array). But remove takes a const and subId is a const, so in principle nothing should change, right? An array function simply removing one of it's members shouldn't change that member?

 

Am I thinking wrong, overlooking something or is this actually an error in ObjectARX?

 

Thankful for any help!

4 REPLIES 4
Message 2 of 5
khunstad
in reply to: khunstad

Ok, I was thinking wrong! The parameter declaration "const AcDbFullSubentPath& subId" only specifies that my function can't change subId. In a program with parallell threads, the "system" is free to change the contents of subId while my function is rolling along.

 

For this case, I fixed the problem with declaring:

 

const AcDbFullSubentPath pathCopy(subId);

 

at the beginning of the function and not using subId directly anymore.

Message 3 of 5
artc2
in reply to: khunstad

Be aware that AcDb is not thread safe, so if there are multiple threads working with AcDb functionality there will almost certainly be problems.

Message 4 of 5
owenwengerd
in reply to: artc2

I think it is highly unlikely that "the system" is changing that memory while your function is executing. From looking at the code you posted, I don't see anything obvious, but you haven't shown the implementation for AcDbFullSubentPathArray::remove(). I suspect there is a bug in your code. I would place a data breakpoint on the changing value to see exactly where it is being changed, and by who.

--
Owen Wengerd
ManuSoft
Message 5 of 5
khunstad
in reply to: khunstad

Ah, finally I saw what I was overlooking! I am calling subHighlight from an InputPointMonitor. After moving code around to test different things, I have ended up with code InputPointMonitor calling:

 

pEntity->unhighlight(highlightedSubents[highlightIndex]);

 

and then removing this exact entry from highlightedSubents during the subUnhighlight call. So it's like subId being a pointer into an array where items are shifting, letting the pointer point to the same spot, but now containing the next item in the array.

 

That clarifies the question. Now I have to figure out if I should call unhighlight or subUnhighlight here, but that's another question...

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

Post to forums  

Autodesk Design & Make Report

”Boost