Skip to content

Commit

Permalink
Fix possible crash
Browse files Browse the repository at this point in the history
To compute the end type, we previously used a lambda function, that was
declared static. Thus, the arguments were apparently captured when
calling it the first time, and didn't change for subsequent calls. As
one of them is a pointer, this could crash if the pointed object had
been destroyed in the meantime.
Although the minimum fix is just to remove the static for the function,
I removed the function itself because it really doesn't make sense
anymore in this context.

CURA-12042
  • Loading branch information
wawanbreton committed Jul 15, 2024
1 parent 6488675 commit a3e668b
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/geometry/MixedLinesSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,17 @@ Shape MixedLinesSet::offset(coord_t distance, ClipperLib::JoinType join_type, do
}
else
{
static auto end_type_fn = [&line, &join_type]()
ClipperLib::EndType end_type;

if (line->hasClosingSegment())
{
end_type = ClipperLib::etClosedLine;
}
else
{
if (line->hasClosingSegment())
{
return ClipperLib::etClosedLine;
}
return join_type == ClipperLib::jtMiter ? ClipperLib::etOpenSquare : ClipperLib::etOpenRound;
};

const ClipperLib::EndType end_type{ end_type_fn() };
end_type = (join_type == ClipperLib::jtMiter) ? ClipperLib::etOpenSquare : ClipperLib::etOpenRound;
}

clipper.AddPath(line->getPoints(), join_type, end_type);
}
}
Expand Down

0 comments on commit a3e668b

Please sign in to comment.