From a22c18475a7d5fe8d6d57e434a23f5a0b867e8fc Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 13 Dec 2022 10:21:02 +0100 Subject: [PATCH] 2DBed and BedShapeDialog: Fixed memory leaks --- src/slic3r/GUI/2DBed.cpp | 16 ++++++++++------ src/slic3r/GUI/BedShapeDialog.cpp | 6 ++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/slic3r/GUI/2DBed.cpp b/src/slic3r/GUI/2DBed.cpp index e7c2cbe542..a4de0a7a65 100644 --- a/src/slic3r/GUI/2DBed.cpp +++ b/src/slic3r/GUI/2DBed.cpp @@ -39,8 +39,8 @@ void Bed_2D::repaint(const std::vector& shape) #else auto color = wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT); //GetSystemColour #endif - dc.SetPen(*new wxPen(color, 1, wxPENSTYLE_SOLID)); - dc.SetBrush(*new wxBrush(color, wxBRUSHSTYLE_SOLID)); + dc.SetPen(wxPen(color, 1, wxPENSTYLE_SOLID)); + dc.SetBrush(wxBrush(color, wxBRUSHSTYLE_SOLID)); auto rect = GetUpdateRegion().GetBox(); dc.DrawRectangle(rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight()); } @@ -75,11 +75,15 @@ void Bed_2D::repaint(const std::vector& shape) // draw bed fill dc.SetBrush(wxBrush(wxColour(255, 255, 255), wxBRUSHSTYLE_SOLID)); + wxPointList pt_list; - for (auto pt : shape) - { - Point pt_pix = to_pixels(pt, ch); - pt_list.push_back(new wxPoint(pt_pix(0), pt_pix(1))); + const size_t pt_cnt = shape.size(); + std::vector points; + points.reserve(pt_cnt); + for (const auto& shape_pt : shape) { + Point pt_pix = to_pixels(shape_pt, ch); + points.emplace_back(wxPoint(pt_pix(0), pt_pix(1))); + pt_list.Append(&points.back()); } dc.DrawPolygon(&pt_list, 0, 0); diff --git a/src/slic3r/GUI/BedShapeDialog.cpp b/src/slic3r/GUI/BedShapeDialog.cpp index 27caedfc3a..aadf605a10 100644 --- a/src/slic3r/GUI/BedShapeDialog.cpp +++ b/src/slic3r/GUI/BedShapeDialog.cpp @@ -123,8 +123,8 @@ void BedShape::apply_optgroup_values(ConfigOptionsGroupShp optgroup) break; default: // rectangle, convex, concave... - optgroup->set_value("rect_size" , new ConfigOptionPoints{ to_2d(m_build_volume.bounding_volume().size()) }); - optgroup->set_value("rect_origin" , new ConfigOptionPoints{ - to_2d(m_build_volume.bounding_volume().min) }); + optgroup->set_value("rect_size" , to_2d(m_build_volume.bounding_volume().size())); + optgroup->set_value("rect_origin" , to_2d(-1 * m_build_volume.bounding_volume().min)); } } @@ -425,8 +425,6 @@ void BedShapePanel::set_shape(const ConfigOptionPoints& points) m_loaded_shape = points.values; update_shape(); - - return; } void BedShapePanel::update_preview()