diff --git a/src/libslic3r/Arrange.cpp b/src/libslic3r/Arrange.cpp index f04e051624..99645f29d8 100644 --- a/src/libslic3r/Arrange.cpp +++ b/src/libslic3r/Arrange.cpp @@ -507,9 +507,7 @@ BedShapeHint::BedShapeHint(const Polyline &bed) { m_type = BedShapes::bsCircle; m_bed.circ = c; } else { - if (m_type == BedShapes::bsIrregular) - m_bed.polygon.Slic3r::Polyline::~Polyline(); - + assert(m_type != BedShapes::bsIrregular); m_type = BedShapes::bsIrregular; ::new (&m_bed.polygon) Polyline(bed); } diff --git a/src/libslic3r/Arrange.hpp b/src/libslic3r/Arrange.hpp index 3d405145e6..a0e4c043f0 100644 --- a/src/libslic3r/Arrange.hpp +++ b/src/libslic3r/Arrange.hpp @@ -39,6 +39,9 @@ enum BedShapes { class BedShapeHint { BedShapes m_type = BedShapes::bsInfinite; + // The union neither calls constructors nor destructors of its members. + // The only member with non-trivial constructor / destructor is the polygon, + // a placement new / delete needs to be called over it. union BedShape_u { // TODO: use variant from cpp17? CircleBed circ; BoundingBox box; @@ -80,6 +83,12 @@ public: BedShapeHint &operator=(const BedShapeHint &cpy) { + if (m_type != cpy.m_type) { + if (m_type == bsIrregular) + m_bed.polygon.Slic3r::Polyline::~Polyline(); + else if (cpy.m_type == bsIrregular) + ::new (&m_bed.polygon) Polyline(); + } m_type = cpy.m_type; switch(m_type) { case bsBox: m_bed.box = cpy.m_bed.box; break; @@ -94,6 +103,12 @@ public: BedShapeHint& operator=(BedShapeHint &&cpy) { + if (m_type != cpy.m_type) { + if (m_type == bsIrregular) + m_bed.polygon.Slic3r::Polyline::~Polyline(); + else if (cpy.m_type == bsIrregular) + ::new (&m_bed.polygon) Polyline(); + } m_type = cpy.m_type; switch(m_type) { case bsBox: m_bed.box = std::move(cpy.m_bed.box); break;