From dc3931ec1f3955ce546fa51661aab56c96f38a5e Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Wed, 11 May 2022 16:49:15 +0200 Subject: [PATCH 1/2] Fix mutable priority queue being wiped when moving out of function Without move constructor, the clean() gets called when returning an instance from a function. --- src/libslic3r/MutablePriorityQueue.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libslic3r/MutablePriorityQueue.hpp b/src/libslic3r/MutablePriorityQueue.hpp index cc1cae68c..a9fcba6ab 100644 --- a/src/libslic3r/MutablePriorityQueue.hpp +++ b/src/libslic3r/MutablePriorityQueue.hpp @@ -17,6 +17,11 @@ public: {} ~MutablePriorityQueue() { clear(); } + MutablePriorityQueue(MutablePriorityQueue &&) = default; + MutablePriorityQueue& operator=(MutablePriorityQueue &&) = default; + MutablePriorityQueue(const MutablePriorityQueue &) = default; + MutablePriorityQueue& operator=(const MutablePriorityQueue &) = default; + void clear(); void reserve(size_t cnt) { m_heap.reserve(cnt); } void push(const T &item); From 1d9d9cf00196ad8a7a0e0b7f589cd0a694c3c5a3 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Wed, 11 May 2022 17:02:21 +0200 Subject: [PATCH 2/2] Prohibit copy for mutable priority queue --- src/libslic3r/MutablePriorityQueue.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/MutablePriorityQueue.hpp b/src/libslic3r/MutablePriorityQueue.hpp index a9fcba6ab..418d8deff 100644 --- a/src/libslic3r/MutablePriorityQueue.hpp +++ b/src/libslic3r/MutablePriorityQueue.hpp @@ -19,8 +19,11 @@ public: MutablePriorityQueue(MutablePriorityQueue &&) = default; MutablePriorityQueue& operator=(MutablePriorityQueue &&) = default; - MutablePriorityQueue(const MutablePriorityQueue &) = default; - MutablePriorityQueue& operator=(const MutablePriorityQueue &) = default; + + // This class modifies the outside data through the m_index_setter + // and thus it should not be copied. The semantics are similar to std::unique_ptr + MutablePriorityQueue(const MutablePriorityQueue &) = delete; + MutablePriorityQueue& operator=(const MutablePriorityQueue &) = delete; void clear(); void reserve(size_t cnt) { m_heap.reserve(cnt); }