mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-20 09:38:07 +08:00
Fixed memory issues of BedShapeHintwhen using unions of non-trivial objects
This commit is contained in:
parent
92bdb68e11
commit
e30a17beb3
@ -507,9 +507,7 @@ BedShapeHint::BedShapeHint(const Polyline &bed) {
|
|||||||
m_type = BedShapes::bsCircle;
|
m_type = BedShapes::bsCircle;
|
||||||
m_bed.circ = c;
|
m_bed.circ = c;
|
||||||
} else {
|
} else {
|
||||||
if (m_type == BedShapes::bsIrregular)
|
assert(m_type != BedShapes::bsIrregular);
|
||||||
m_bed.polygon.Slic3r::Polyline::~Polyline();
|
|
||||||
|
|
||||||
m_type = BedShapes::bsIrregular;
|
m_type = BedShapes::bsIrregular;
|
||||||
::new (&m_bed.polygon) Polyline(bed);
|
::new (&m_bed.polygon) Polyline(bed);
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,9 @@ enum BedShapes {
|
|||||||
class BedShapeHint {
|
class BedShapeHint {
|
||||||
BedShapes m_type = BedShapes::bsInfinite;
|
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?
|
union BedShape_u { // TODO: use variant from cpp17?
|
||||||
CircleBed circ;
|
CircleBed circ;
|
||||||
BoundingBox box;
|
BoundingBox box;
|
||||||
@ -80,6 +83,12 @@ public:
|
|||||||
|
|
||||||
BedShapeHint &operator=(const BedShapeHint &cpy)
|
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;
|
m_type = cpy.m_type;
|
||||||
switch(m_type) {
|
switch(m_type) {
|
||||||
case bsBox: m_bed.box = cpy.m_bed.box; break;
|
case bsBox: m_bed.box = cpy.m_bed.box; break;
|
||||||
@ -94,6 +103,12 @@ public:
|
|||||||
|
|
||||||
BedShapeHint& operator=(BedShapeHint &&cpy)
|
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;
|
m_type = cpy.m_type;
|
||||||
switch(m_type) {
|
switch(m_type) {
|
||||||
case bsBox: m_bed.box = std::move(cpy.m_bed.box); break;
|
case bsBox: m_bed.box = std::move(cpy.m_bed.box); break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user