grid_map
grid_map copied to clipboard
Do not iterate over the map when size is 0
Hey,
I have noticed small bug within GridMapIterator. There are two situations in which GridMap object is empty (size is 0,0):
- When geometry of GridMap is not set, so it's by default (0,0)
- Due to very small length values, so size may be rounded to (0,0) https://github.com/ANYbotics/grid_map/blob/master/grid_map_core/src/GridMap.cpp#L51
When using GridMapIterator as shown in README.md and demos https://github.com/ANYbotics/grid_map/blob/master/grid_map_demos/src/IteratorsDemo.cpp#L58, first iteration is always valid as isPastEnd_
variable is false
regardless of the GridMap's size https://github.com/ANYbotics/grid_map/blob/master/grid_map_core/src/iterators/GridMapIterator.cpp#L20. Accessing empty GridMap leads to exception which crashes whole application as currently it's not catched or even documented.
I have added validation in GridMapIterator constructor which ensures GridMap is accessible. I have also added simple test to check if isPastEnd_
variable initializes with true
value when passed GridMap is empty.
Thank you, will import it.