Fix: Geometry Nodes: Memory leak when deleting instances

The instance attributes assignment operators were broken in multiple
ways: there wasn't a move constructor (probably causing performance
issues), and the destination attributes weren't freed before they
were replaced.
This commit is contained in:
Hans Goudey 2022-10-19 13:12:20 -05:00
parent a803dbe7ed
commit c14b113746
2 changed files with 16 additions and 3 deletions

View File

@ -793,7 +793,9 @@ class CustomDataAttributes {
~CustomDataAttributes();
CustomDataAttributes(const CustomDataAttributes &other);
CustomDataAttributes(CustomDataAttributes &&other);
CustomDataAttributes &operator=(const CustomDataAttributes &other);
CustomDataAttributes &operator=(CustomDataAttributes &&other);
void reallocate(int size);

View File

@ -642,15 +642,26 @@ CustomDataAttributes::CustomDataAttributes(CustomDataAttributes &&other)
size_ = other.size_;
data = other.data;
CustomData_reset(&other.data);
other.size_ = 0;
}
CustomDataAttributes &CustomDataAttributes::operator=(const CustomDataAttributes &other)
{
if (this != &other) {
CustomData_copy(&other.data, &data, CD_MASK_ALL, CD_DUPLICATE, other.size_);
size_ = other.size_;
if (this == &other) {
return *this;
}
this->~CustomDataAttributes();
new (this) CustomDataAttributes(other);
return *this;
}
CustomDataAttributes &CustomDataAttributes::operator=(CustomDataAttributes &&other)
{
if (this == &other) {
return *this;
}
this->~CustomDataAttributes();
new (this) CustomDataAttributes(std::move(other));
return *this;
}