From d6524f8963beea9982decd8ff34b92be56d8acaf Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Tue, 1 Apr 2025 16:18:22 +0800 Subject: [PATCH] Fix `render_hover_point` memory leaking by using `std::optional` --- src/slic3r/GUI/Gizmos/GLGizmoBrimEars.cpp | 7 +++---- src/slic3r/GUI/Gizmos/GLGizmoBrimEars.hpp | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBrimEars.cpp b/src/slic3r/GUI/Gizmos/GLGizmoBrimEars.cpp index 89f1aee1d..f29600189 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBrimEars.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBrimEars.cpp @@ -113,7 +113,7 @@ bool GLGizmoBrimEars::is_use_point(const BrimPoint &point) const void GLGizmoBrimEars::render_points(const Selection &selection, bool picking) const { auto editing_cache = m_editing_cache; - if (render_hover_point != nullptr) { editing_cache.push_back(*render_hover_point); } + if (render_hover_point) { editing_cache.push_back(*render_hover_point); } size_t cache_size = editing_cache.size(); @@ -308,10 +308,9 @@ bool GLGizmoBrimEars::gizmo_event(SLAGizmoEventType action, const Vec2d &mouse_p Transform3d inverse_trsf = volume->get_instance_transformation().get_matrix(true).inverse(); std::pair pos_and_normal; if (unproject_on_mesh2(mouse_position, pos_and_normal)) { - render_hover_point = new CacheEntry(BrimPoint(pos_and_normal.first, m_new_point_head_diameter / 2.f), false, (inverse_trsf * m_world_normal).cast(), true); + render_hover_point = CacheEntry(BrimPoint(pos_and_normal.first, m_new_point_head_diameter / 2.f), false, (inverse_trsf * m_world_normal).cast(), true); } else { - delete render_hover_point; - render_hover_point = nullptr; + render_hover_point.reset(); } } else if (action == SLAGizmoEventType::LeftDown && (shift_down || alt_down || control_down)) { // left down with shift - show the selection rectangle: diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBrimEars.hpp b/src/slic3r/GUI/Gizmos/GLGizmoBrimEars.hpp index eb5a002db..f76516cce 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBrimEars.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBrimEars.hpp @@ -107,7 +107,7 @@ private: const Vec3d m_world_normal = {0, 0, 1}; std::map> m_mesh_raycaster_map; GLVolume* m_last_hit_volume; - CacheEntry* render_hover_point = nullptr; + std::optional render_hover_point; bool m_link_text_hover = false;