[Bf-blender-cvs] [a094cdacf89] master: BLI: fix memory error when moving VArray_Span

Jacques Lucke noreply at git.blender.org
Mon Jun 6 14:01:50 CEST 2022


Commit: a094cdacf89a18e6fdb167ef8abdc4a79b905fa6
Author: Jacques Lucke
Date:   Mon Jun 6 14:01:25 2022 +0200
Branches: master
https://developer.blender.org/rBa094cdacf89a18e6fdb167ef8abdc4a79b905fa6

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.

===================================================================

M	source/blender/blenlib/BLI_virtual_array.hh

===================================================================

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<typename T> class VArray_Span final : public Span<T> {
       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;
+  }
 };
 
 /**



More information about the Bf-blender-cvs mailing list