Skip to content
This repository has been archived by the owner on Aug 3, 2020. It is now read-only.

urdf_to_collada crashes with negative cylinder lengths #175

Closed
mrjogo opened this issue Jan 9, 2017 · 2 comments
Closed

urdf_to_collada crashes with negative cylinder lengths #175

mrjogo opened this issue Jan 9, 2017 · 2 comments
Labels

Comments

@mrjogo
Copy link

mrjogo commented Jan 9, 2017

When urdf_to_collada is run with the following link, it crashes because of the negative length:

<link name="link0">
  <visual>
    <geometry>
      <cylinder length="-0.005" radius="0.01"/>
    </geometry>
  </visual>
</link>

The error message is

terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted (core dumped)

It's possible that negative lengths are not valid URDF, but it is not specified in the URDF documentation and the other systems that use URDF happily interpret the length as starting from the origin and going in the negative direction.

@clalancette
Copy link
Contributor

clalancette commented Jan 10, 2017

I took a quick look at this. It turns out that the problem is down in geometric_shapes, where we have this code:

  double h = cylinder.length;
  ...
  unsigned int h_num = ceil(h / circle_edge);
  ...
  for (unsigned int i = 0; i < h_num - 1 ; ++i)
    for(unsigned int j = 0; j < tot; ++j)
      vertices.push_back(Eigen::Vector3d(r * cos(phi + phid * j), r * sin(phi + phid * j), h / 2 - (i + 1) * hd));

So we are taking a negative double, dividing it by some (positive) amount, and then assigning the result to an unsigned. This turns out to be a huge number (instead of the small negative number), which we then end up iterating over and doing a vector push_back, using up a crazy amount of memory. A simple fix here is call fabs() on h before calculating h_num, which will avoid this particular problem, but may or may not actually "work". I'll get in touch with the geometric_shapes maintainers and see if they have any advice.

@wjwwood
Copy link
Member

wjwwood commented Jan 26, 2017

Close this in favor of moveit/geometric_shapes#64

@wjwwood wjwwood closed this as completed Jan 26, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants