Skip to content

Commit 1d6f038

Browse files
committed
FIX: Don't crash with optional field vectors empty
1 parent 14d7327 commit 1d6f038

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

modules/mrpt_maps/src/maps/CPointsMap.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,10 +2076,14 @@ CPointsMap::InsertCtx CPointsMap::prepareForInsertPointsFrom(const CPointsMap& s
20762076
if (auto it = std::find(src_float_names.begin(), src_float_names.end(), name);
20772077
it != src_float_names.end())
20782078
{
2079+
const auto* srcVector = source.getPointsBufferRef_float_field(name);
2080+
if (!srcVector || srcVector->empty())
2081+
{
2082+
continue;
2083+
}
20792084
ctx.float_fields.push_back(
2080-
{source.getPointsBufferRef_float_field(name),
2081-
const_cast<mrpt::aligned_std_vector<float>*>(
2082-
this->getPointsBufferRef_float_field(name))});
2085+
{srcVector, const_cast<mrpt::aligned_std_vector<float>*>(
2086+
this->getPointsBufferRef_float_field(name))});
20832087
}
20842088
}
20852089

@@ -2090,10 +2094,14 @@ CPointsMap::InsertCtx CPointsMap::prepareForInsertPointsFrom(const CPointsMap& s
20902094
if (auto it = std::find(src_u16_names.begin(), src_u16_names.end(), name);
20912095
it != src_u16_names.end())
20922096
{
2097+
const auto* srcVector = source.getPointsBufferRef_uint_field(name);
2098+
if (!srcVector || srcVector->empty())
2099+
{
2100+
continue;
2101+
}
20932102
ctx.uint16_fields.push_back(
2094-
{source.getPointsBufferRef_uint_field(name),
2095-
const_cast<mrpt::aligned_std_vector<uint16_t>*>(
2096-
this->getPointsBufferRef_uint_field(name))});
2103+
{srcVector, const_cast<mrpt::aligned_std_vector<uint16_t>*>(
2104+
this->getPointsBufferRef_uint_field(name))});
20972105
}
20982106
}
20992107

0 commit comments

Comments
 (0)