Setting DataVariance=DYNAMIC causes simulation to slow and then stop

When running a simulation I am drawing a line that follows the COM of my skeleton and thus, shows the traveled path. Setting dataVariance to DYNAMIC or DYNAMIC_ELEMENTS causes the simulation to slow and then stop after approximately 10 seconds.

I set up lineSegmentShape before the simulation loop like this

  mTravelledLineFrame = std::make_shared<dart::dynamics::SimpleFrame>(
            dart::dynamics::Frame::World());

  mTravelledPathLine = std::make_shared<dart::dynamics::LineSegmentShape>(3.0);

  Eigen::Vector3d eigVertCoords(&mElevSurfacePtr->smoothPath[0][0]); 
  mTravelledPathLine->addVertex(eigVertCoords);
  //mak 
  mTravelledPathLine->addDataVariance(dart::dynamics::Shape::DYNAMIC_VERTICES);  

  mTravelledLineFrame->setShape(mTravelledPathLine);
  mTravelledLineFrame->createVisualAspect();
  Eigen::Vector4d travelledLineColor = Eigen::Vector4d(0.1, 1.0, 0.0, 1.0);
  mTravelledLineFrame->getVisualAspect()->setColor(travelledLineColor);
  
  mWorld->addSimpleFrame(mTravelledLineFrame); 

And I update before each frame refresh with

mTravelledPathLine->addVertex(eigCOM);

Which simulates without stopping but does not draw the line, as expected due to dataVariance = DYNAMIC_VERTICES not allowing the addition of vertices.

Changing to the following dataVariance options draws the line but causes the slow down.

mTravelledPathLine->addDataVariance(dart::dynamics::Shape::DYNAMIC_ELEMENTS);

and

mTravelledPathLine->addDataVariance(dart::dynamics::Shape::DYNAMIC);

Before changing to OSG I was using openGL to draw the line before each refresh, as below, which was working fine.

  glBegin(GL_LINES);
  for(std::size_t i=0; i< mElevSurfacePtr->travelledPath.size()-1; i++){
    glVertex3dv(&mElevSurfacePtr->travelledPath[i][0]);
    glVertex3dv(&mElevSurfacePtr->travelledPath[i+1][0]);
  }
  glEnd();

Also, in the api docs it says

DYNAMIC_ELEMENTS : Vertex positions of a mesh might change (this does not include adding or removing vertices) (this enum is not relevant for primitive shapes)

But in Dynamics/Shape.hpp it says

DYNAMIC_ELEMENTS = 1 << 5, The number of elements and/or arrangement of elements might change (this includes adding and removing vertices) (this enum is not relevant for primitive shapes)

Is the slow down a bug or is there a different way I should be drawing a dynamic line.

Many Thanks

It looks like the API docs have an off-by-one error because we used the wrong doxygen syntax in the header file. (I think we need to use //< instead of /// or something like that).

Based on the code it seems that either DYNAMIC_VERTICES or DYNAMICS_ELEMENTS should do the same thing.

I suppose the slowdown could be considered a bug, or at least unintentionally poor performance.

How large is your list of vertices growing? If it’s getting very large, then maybe it’s quickly becoming too expensive to resize and convert each element of the list on every render cycle. We could try to figure out a smarter behavior for better performance.

Yes I was a little bit confused with the code you linked. It seems that even with DYNAMIC_VERTICES selected, mVertices is getting resized, which I don’t think is supposed to happen?

However, my simulation runs fine (without drawing the line) when DYNAMIC_VERTICES is selected so the problem is probably occurring in the if statement above the one you linked, or where the line is drawn to screen.

The list of vertices increases by one every time a frame is refreshed so approximately 30 per second. By the time my sim stops the list only has a size of ~500.

Oh sorry I totally overlooked this chunk of code which is probably where the actual issue is happening.

It seems that this line is likely the culprit, because it’s adding a primitive set without removing the previous one. So the set of line segments that need to be drawn get piled up on top of each other instead of having the new set replace the old set. That’s definitely a bug.

1 Like

Okay, that makes sense, I will make a github issue.

This should be fixed by https://github.com/dartsim/dart/pull/1381!

1 Like