Closed aharmat closed 4 years ago
Your code fails because you are accessing temporary objects that have gone out of scope.
Note that the const variant of innerBounds
returns not a const reference but a new object. In the line const auto& inner_bound2 = area.innerBounds()[idx];
(where area is const
), you are indexing into area.innerBounds()
which is a temporary object that goes out of scope at the end of the expression.
The result of your comparison afterwards inner_bound != inner_bound2
is therefore completely random because inner_bound2
no longer exists as an object. If you change your line to auto inner_bound2 = area.innerBounds()[idx];
, your code should pass.
Thank you, that makes sense.
I recently ran into an issue that I believe is a bug in lanelet2. When accessing the inner bounds of an Area by indexing into
innerBounds()[i]
, the returned result is different than if accessinginnerBounds()
with a range-based for loop. But this only happens when we're dealing with aconst Area
! Attached is a minimal example that replicates the issue, it borrows most code from lanelet2_examples:Since this only happens for const Areas, I'm guessing the problem is somewhere in
but I haven't been able to figure it out.