Skip to content

Commit

Permalink
Fix possible crashes when using bad meshes
Browse files Browse the repository at this point in the history
  • Loading branch information
wawanbreton committed Oct 30, 2024
1 parent 917c3af commit 1ae45ef
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
13 changes: 13 additions & 0 deletions src/WallToolPaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,19 @@ const Shape& WallToolPaths::getInnerContour()

bool WallToolPaths::removeEmptyToolPaths(std::vector<VariableWidthLines>& toolpaths)
{
for (VariableWidthLines& toolpath : toolpaths)
{
toolpath.erase(
std::remove_if(
toolpath.begin(),
toolpath.end(),
[](const ExtrusionLine& line)
{
return line.junctions_.empty();
}),
toolpath.end());
}

toolpaths.erase(
std::remove_if(
toolpaths.begin(),
Expand Down
22 changes: 8 additions & 14 deletions src/WallsComputation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,15 @@ void WallsComputation::generateWalls(SliceLayer* layer, SectionType section)

// Remove the parts which did not generate a wall. As these parts are too small to print,
// and later code can now assume that there is always minimal 1 wall line.
if (settings_.get<size_t>("wall_line_count") >= 1 && ! settings_.get<bool>("fill_outline_gaps"))
{
for (size_t part_idx = 0; part_idx < layer->parts.size(); part_idx++)
bool check_wall_and_spiral = settings_.get<size_t>("wall_line_count") >= 1 && ! settings_.get<bool>("fill_outline_gaps");
auto iterator_remove = std::remove_if(
layer->parts.begin(),
layer->parts.end(),
[&check_wall_and_spiral](const SliceLayerPart& part)
{
if (layer->parts[part_idx].wall_toolpaths.empty() && layer->parts[part_idx].spiral_wall.empty())
{
if (part_idx != layer->parts.size() - 1)
{ // move existing part into part to be deleted
layer->parts[part_idx] = std::move(layer->parts.back());
}
layer->parts.pop_back(); // always remove last element from array (is more efficient)
part_idx -= 1; // check the part we just moved here
}
}
}
return (check_wall_and_spiral && part.wall_toolpaths.empty() && part.spiral_wall.empty()) || part.outline.empty() || part.print_outline.empty();
});
layer->parts.erase(iterator_remove, layer->parts.end());
}

void WallsComputation::generateSpiralInsets(SliceLayerPart* part, coord_t line_width_0, coord_t wall_0_inset, bool recompute_outline_based_on_outer_wall)
Expand Down

0 comments on commit 1ae45ef

Please sign in to comment.