From a094cdacf89a18e6fdb167ef8abdc4a79b905fa6 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Mon, 6 Jun 2022 14:01:25 +0200 Subject: [PATCH] BLI: fix memory error when moving VArray_Span The issue was that the new span still referenced data that was potentially stored in the old VArray_Span. --- source/blender/blenlib/BLI_virtual_array.hh | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/source/blender/blenlib/BLI_virtual_array.hh b/source/blender/blenlib/BLI_virtual_array.hh index 0705d423f01..8f228ea188e 100644 --- a/source/blender/blenlib/BLI_virtual_array.hh +++ b/source/blender/blenlib/BLI_virtual_array.hh @@ -1153,6 +1153,30 @@ template class VArray_Span final : public Span { this->data_ = owned_data_.data(); } } + + VArray_Span(VArray_Span &&other) + : varray_(std::move(other.varray_)), owned_data_(std::move(other.owned_data_)) + { + this->size_ = varray_.size(); + if (varray_.is_span()) { + this->data_ = varray_.get_internal_span().data(); + } + else { + this->data_ = owned_data_.data(); + } + other.data_ = nullptr; + other.size_ = 0; + } + + VArray_Span &operator=(VArray_Span &&other) + { + if (this == &other) { + return *this; + } + std::destroy_at(this); + new (this) VArray_Span(std::move(other)); + return *this; + } }; /**