Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault on ARM due to oversized Eigen matrix #42

Closed
MariusHuber opened this issue May 25, 2017 · 2 comments
Closed

Segmentation fault on ARM due to oversized Eigen matrix #42

MariusHuber opened this issue May 25, 2017 · 2 comments

Comments

@MariusHuber
Copy link
Contributor

MariusHuber commented May 25, 2017

System

  • Hardkernel Odroid XU4
  • Ubuntu 14.04 LTS

Problem

Elevation mapping throws std::bad_alloc() as soon as the map is supposed to be moved. Adding point clouds to a map fixed in position works.

Where in the code the problem occurs

Using gdb leads to ElevationMap.cpp:286. At the core, the problem is that grid_map::EllipseIterator.cpp:32 is not initialized. This function is called by ElevationMap.cpp:285. Eigen allocates an immense amount of memory and finally throws std::bad_alloc() from Eigen/src/Core/util/Memory.h:362-367.

// Eigen/src/Core/util/Memory.h, lines 362 to 367
template<typename T>
EIGEN_ALWAYS_INLINE void check_size_for_overflow(size_t size)
{
  if(size > size_t(-1) / sizeof(T))
    throw_std_bad_alloc();
}

Hacky fix

A quick, hacky fix is to skip the map fusion process of a specific cell in case too much memory is allocated. This code is added between ElevationMap.cpp:285 and ElevationMap.cpp:286:

// If maxNumberOfCellsToFuse is too high, Eigen will throw a std::bad_alloc() error.
// Therefore, skip fusing in that case.
if (maxNumberOfCellsToFuse > (size_t(-1) / sizeof(float))) {
  // Skip fusing.
  fusedMap_.at("elevation", *areaIterator) = rawMapCopy.at("elevation", *areaIterator);
  fusedMap_.at("lower_bound", *areaIterator) = rawMapCopy.at("elevation", *areaIterator) - 2.0 * sqrt(rawMapCopy.at("variance", *areaIterator));
  fusedMap_.at("upper_bound", *areaIterator) = rawMapCopy.at("elevation", *areaIterator) + 2.0 * sqrt(rawMapCopy.at("variance", *areaIterator));
  fusedMap_.at("color", *areaIterator) = rawMapCopy.at("color", *areaIterator);
  continue;
}

This is only a temporary fix. The issue should be fixed more permanently in grid_map.

@MariusHuber
Copy link
Contributor Author

@pfankhauser hope this helps.

@maximilianwulf
Copy link
Contributor

Closing due to inactivity. Feel free to re-open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants