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.
This commit is contained in:
2022-06-06 14:01:25 +02:00
parent 7eb2018a0b
commit a094cdacf8

View File

@@ -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;
}
};
/**