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.
23 KiB
23 KiB