Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/CuraEngine.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLipu Fei <lipu.fei815@gmail.com>2017-12-15 14:53:03 +0300
committerLipu Fei <lipu.fei815@gmail.com>2017-12-15 15:12:57 +0300
commit60c3b1c1bb5e7d3cfffd4c632afbbec7abc18fd5 (patch)
tree45a87b1652d994b5a26fa5b40d852eebcbf69d72
parentdbd0d61c20875acbb2d77dec78adb29c39794a75 (diff)
Fix possible segfault due to accessing deleted TopSurface3.1
CURA-4702 Some SliceLayers can be deleted during removeEmptyFirstLayers() which will delete the TopSurfaces in those SliceLayers too. This is done in a vector.erase() call, and it will move the undeleted SliceLayers back to the front. Because TopSurface is a pointer in SliceLayers, in the reconstructed SliceLayer vector, although they keep the same TopSurface pointers as before, the actual TopSurface memory blocks were deallocated. This can cause segfauls when ironing gets processed.
-rw-r--r--src/FffGcodeWriter.cpp4
-rw-r--r--src/FffPolygonGenerator.cpp4
-rw-r--r--src/TopSurface.cpp4
-rw-r--r--src/TopSurface.h19
-rw-r--r--src/sliceDataStorage.cpp4
-rw-r--r--src/sliceDataStorage.h2
6 files changed, 17 insertions, 20 deletions
diff --git a/src/FffGcodeWriter.cpp b/src/FffGcodeWriter.cpp
index ce79f4718..d889efd68 100644
--- a/src/FffGcodeWriter.cpp
+++ b/src/FffGcodeWriter.cpp
@@ -1806,9 +1806,9 @@ bool FffGcodeWriter::processIroning(const SliceMeshStorage& mesh, const SliceLay
bool added_something = false;
const bool ironing_enabled = mesh.getSettingBoolean("ironing_enabled");
const bool ironing_only_highest_layer = mesh.getSettingBoolean("ironing_only_highest_layer");
- if (ironing_enabled && (!ironing_only_highest_layer || mesh.layer_nr_max_filled_layer == gcode_layer.getLayerNr()) && layer.top_surface)
+ if (ironing_enabled && (!ironing_only_highest_layer || mesh.layer_nr_max_filled_layer == gcode_layer.getLayerNr()))
{
- added_something |= layer.top_surface->ironing(mesh, line_config, gcode_layer);
+ added_something |= layer.top_surface.ironing(mesh, line_config, gcode_layer);
}
return added_something;
}
diff --git a/src/FffPolygonGenerator.cpp b/src/FffPolygonGenerator.cpp
index 000f8ae83..be060bb71 100644
--- a/src/FffPolygonGenerator.cpp
+++ b/src/FffPolygonGenerator.cpp
@@ -757,8 +757,8 @@ void FffPolygonGenerator::processSkinsAndInfill(const SliceDataStorage& storage,
if (mesh.getSettingBoolean("ironing_enabled") && (!mesh.getSettingBoolean("ironing_only_highest_layer") || (unsigned int)mesh.layer_nr_max_filled_layer == layer_nr))
{
- TopSurface* top_surface = new TopSurface(mesh, layer_nr); //Generate the top surface to iron over.
- mesh.layers[layer_nr].top_surface = top_surface;
+ // Generate the top surface to iron over.
+ mesh.layers[layer_nr].top_surface.setAreasFromMeshAndLayerNumber(mesh, layer_nr);
}
}
diff --git a/src/TopSurface.cpp b/src/TopSurface.cpp
index 1122ea032..c1dabd56b 100644
--- a/src/TopSurface.cpp
+++ b/src/TopSurface.cpp
@@ -13,7 +13,7 @@ TopSurface::TopSurface()
//Do nothing. Areas stays empty.
}
-TopSurface::TopSurface(SliceMeshStorage& mesh, size_t layer_number)
+void TopSurface::setAreasFromMeshAndLayerNumber(SliceMeshStorage& mesh, size_t layer_number)
{
//The top surface is all parts of the mesh where there's no mesh above it, so find the layer above it first.
Polygons mesh_above;
@@ -25,7 +25,7 @@ TopSurface::TopSurface(SliceMeshStorage& mesh, size_t layer_number)
areas = mesh.layers[layer_number].getOutlines().difference(mesh_above);
}
-bool TopSurface::ironing(const SliceMeshStorage& mesh, const GCodePathConfig& line_config, LayerPlan& layer)
+bool TopSurface::ironing(const SliceMeshStorage& mesh, const GCodePathConfig& line_config, LayerPlan& layer) const
{
if (areas.empty())
{
diff --git a/src/TopSurface.h b/src/TopSurface.h
index 9066eb5a7..10ac21720 100644
--- a/src/TopSurface.h
+++ b/src/TopSurface.h
@@ -21,7 +21,8 @@ public:
TopSurface();
/*!
- * \brief Generate new top surface for a specific layer.
+ * \brief Sets the areas for this TopSurface to process from the given
+ * mesh and layer number.
*
* The surface will be generated by subtracting the layer above from the
* current layer. Anything that is leftover is then part of the top surface
@@ -30,12 +31,7 @@ public:
* \param mesh The mesh to generate the top surface area for.
* \param layer_number The layer to generate the top surface area for.
*/
- TopSurface(SliceMeshStorage& mesh, size_t layer_number);
-
- /*!
- * \brief The areas of top surface, for each layer.
- */
- Polygons areas;
+ void setAreasFromMeshAndLayerNumber(SliceMeshStorage& mesh, size_t layer_number);
/*!
* \brief Generate paths for ironing over the top surface.
@@ -50,10 +46,15 @@ public:
* that the flow might still get adjusted by the ironing settings.
* \param[out] layer The output g-code layer to put the resulting lines in.
*/
- bool ironing(const SliceMeshStorage& mesh, const GCodePathConfig& line_config, LayerPlan& layer);
+ bool ironing(const SliceMeshStorage& mesh, const GCodePathConfig& line_config, LayerPlan& layer) const;
+
+public:
+ /*!
+ * \brief The areas of top surface, for each layer.
+ */
+ Polygons areas;
};
}
#endif /* TOPSURFACE_H */
-
diff --git a/src/sliceDataStorage.cpp b/src/sliceDataStorage.cpp
index fa7742604..fc6f7da83 100644
--- a/src/sliceDataStorage.cpp
+++ b/src/sliceDataStorage.cpp
@@ -47,10 +47,6 @@ const Polygons& SliceLayerPart::getOwnInfillArea() const
SliceLayer::~SliceLayer()
{
- if (top_surface)
- {
- delete top_surface;
- }
}
Polygons SliceLayer::getOutlines(bool external_polys_only) const
diff --git a/src/sliceDataStorage.h b/src/sliceDataStorage.h
index 8d7d7d64b..c270e5b4b 100644
--- a/src/sliceDataStorage.h
+++ b/src/sliceDataStorage.h
@@ -150,7 +150,7 @@ public:
*
* This is filled only when the top surface is needed.
*/
- TopSurface* top_surface = nullptr;
+ TopSurface top_surface;
/*!
* Get the all outlines of all layer parts in this layer.