[Bf-blender-cvs] [c822e03e2a5] master: Fix: Missing handling of dynamic instance attribute size

Hans Goudey noreply at git.blender.org
Tue Nov 30 16:59:17 CET 2021


Commit: c822e03e2a58e23d9ef82b30b012f59ae7d1c425
Author: Hans Goudey
Date:   Tue Nov 30 10:59:11 2021 -0500
Branches: master
https://developer.blender.org/rBc822e03e2a58e23d9ef82b30b012f59ae7d1c425

Fix: Missing handling of dynamic instance attribute size

The attributes need to be reallocated when the size changes.

Differential Revision: https://developer.blender.org/D13390

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

M	source/blender/blenkernel/BKE_attribute_access.hh
M	source/blender/blenkernel/intern/attribute_access.cc
M	source/blender/blenkernel/intern/geometry_component_instances.cc

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

diff --git a/source/blender/blenkernel/BKE_attribute_access.hh b/source/blender/blenkernel/BKE_attribute_access.hh
index 47f62b52a0f..4402f6fbf74 100644
--- a/source/blender/blenkernel/BKE_attribute_access.hh
+++ b/source/blender/blenkernel/BKE_attribute_access.hh
@@ -345,6 +345,8 @@ class CustomDataAttributes {
 
   void reallocate(const int size);
 
+  void clear();
+
   std::optional<blender::fn::GSpan> get_for_read(const AttributeIDRef &attribute_id) const;
 
   blender::fn::GVArray get_for_read(const AttributeIDRef &attribute_id,
diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc
index 47ddb2494d0..902e08f1b28 100644
--- a/source/blender/blenkernel/intern/attribute_access.cc
+++ b/source/blender/blenkernel/intern/attribute_access.cc
@@ -821,6 +821,12 @@ void CustomDataAttributes::reallocate(const int size)
   CustomData_realloc(&data, size);
 }
 
+void CustomDataAttributes::clear()
+{
+  CustomData_free(&data, size_);
+  size_ = 0;
+}
+
 bool CustomDataAttributes::foreach_attribute(const AttributeForeachCallback callback,
                                              const AttributeDomain domain) const
 {
diff --git a/source/blender/blenkernel/intern/geometry_component_instances.cc b/source/blender/blenkernel/intern/geometry_component_instances.cc
index 9a30c86c1e5..29c28a875c1 100644
--- a/source/blender/blenkernel/intern/geometry_component_instances.cc
+++ b/source/blender/blenkernel/intern/geometry_component_instances.cc
@@ -63,6 +63,7 @@ void InstancesComponent::reserve(int min_capacity)
   if (!instance_ids_.is_empty()) {
     this->instance_ids_ensure();
   }
+  attributes_.reallocate(min_capacity);
 }
 
 /**
@@ -78,6 +79,7 @@ void InstancesComponent::resize(int capacity)
   if (!instance_ids_.is_empty()) {
     this->instance_ids_ensure();
   }
+  attributes_.reallocate(capacity);
 }
 
 void InstancesComponent::clear()
@@ -85,6 +87,7 @@ void InstancesComponent::clear()
   instance_reference_handles_.clear();
   instance_transforms_.clear();
   instance_ids_.clear();
+  attributes_.clear();
 
   references_.clear();
 }
@@ -98,6 +101,7 @@ void InstancesComponent::add_instance(const int instance_handle, const float4x4
   if (!instance_ids_.is_empty()) {
     this->instance_ids_ensure();
   }
+  attributes_.reallocate(this->instances_amount());
 }
 
 blender::Span<int> InstancesComponent::instance_reference_handles() const



More information about the Bf-blender-cvs mailing list