fix: a merged segment lost the scan it was built from, so pointAt read past the end
The constructor mergeLines uses took only the fitted parameters and the ray indices, leaving c_data_ and r_data_ default-constructed. pointAt indexes r_data_.xs directly, so asking a merged segment where one of its own rays is read past the end of an empty vector. Two callers already do exactly that. The reflective-tape check walks the ray span of a wing and reads each point; the arc matcher gathers the points of adjacent segments to fit a circle to them. The arc matcher is how it surfaced - it segfaulted, and AddressSanitizer put it on line.cpp:58. It stayed hidden because mergeLines almost never fires with the default parameters: a gap wide enough to split at is already wider than max_line_gap, which is the gate merging has to pass. That is the merge gate working as intended, and it is also why this could not be reached from a synthesized scene - a scene-based test here would guard nothing, so the regression test builds a merged Line directly instead. The constructor now takes the scan data, like the other one. A merged segment is still built from the same scan, so there was never a reason for it to lose it, and a consumer cannot tell a merged segment from a fresh one - the invariant has to be that every segment answers for every ray it supports. pointAt also bounds-checks now and returns NaN for a ray it does not carry. That is a second line of defence, not the fix: every caller already has to reject non-finite points because a real scan contains them, so a future constructor that forgets the data degrades instead of reading out of bounds.
This commit is contained in:
16
src/line.cpp
16
src/line.cpp
@@ -10,6 +10,7 @@
|
||||
#include <robot_line_extraction/line.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include <utility>
|
||||
|
||||
namespace robot_line_extraction
|
||||
@@ -36,10 +37,12 @@ Line::Line(const CachedData& c_data, const RangeData& r_data, const LineExtracti
|
||||
{
|
||||
}
|
||||
|
||||
Line::Line(double angle, double radius, const std::array<double, 4>& covariance,
|
||||
const std::array<double, 2>& start, const std::array<double, 2>& end,
|
||||
const std::vector<unsigned int>& indices)
|
||||
: indices_(indices)
|
||||
Line::Line(const CachedData& c_data, const RangeData& r_data, double angle, double radius,
|
||||
const std::array<double, 4>& covariance, const std::array<double, 2>& start,
|
||||
const std::array<double, 2>& end, const std::vector<unsigned int>& indices)
|
||||
: c_data_(c_data)
|
||||
, r_data_(r_data)
|
||||
, indices_(indices)
|
||||
, angle_(angle)
|
||||
, radius_(radius)
|
||||
, start_(start)
|
||||
@@ -55,6 +58,11 @@ Line::Line(double angle, double radius, const std::array<double, 4>& covariance,
|
||||
|
||||
std::array<double, 2> Line::pointAt(unsigned int index) const
|
||||
{
|
||||
if (index >= r_data_.xs.size() || index >= r_data_.ys.size())
|
||||
{
|
||||
const double nan = std::numeric_limits<double>::quiet_NaN();
|
||||
return { { nan, nan } };
|
||||
}
|
||||
return { { r_data_.xs[index], r_data_.ys[index] } };
|
||||
}
|
||||
|
||||
|
||||
@@ -405,7 +405,8 @@ void LineExtractor::mergeLines()
|
||||
indices.insert(indices.end(), ind_1.begin(), ind_1.end());
|
||||
indices.insert(indices.end(), ind_2.begin(), ind_2.end());
|
||||
|
||||
Line merged_line(L_m[1], L_m[0], cov, lines_[i - 1].getStart(), lines_[i].getEnd(), indices);
|
||||
Line merged_line(c_data_, r_data_, L_m[1], L_m[0], cov, lines_[i - 1].getStart(),
|
||||
lines_[i].getEnd(), indices);
|
||||
merged_line.projectEndpoints();
|
||||
lines_[i] = merged_line;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user