[Bf-blender-cvs] [7911954b403] master: Fix T103452: Active & default color attributes reset on modifier apply

Hans Goudey noreply at git.blender.org
Mon Dec 26 16:49:30 CET 2022


Commit: 7911954b403efe1c93bf5f94961520e7b96c50ec
Author: Hans Goudey
Date:   Mon Dec 26 10:49:21 2022 -0500
Branches: master
https://developer.blender.org/rB7911954b403efe1c93bf5f94961520e7b96c50ec

Fix T103452: Active & default color attributes reset on modifier apply

I missed adding the "convert type/domain to mask" macros.
Also refactor slightly to split the matching attribute test to a
separate function to ease debugging and reduce duplication.

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

M	source/blender/editors/object/object_modifier.cc

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

diff --git a/source/blender/editors/object/object_modifier.cc b/source/blender/editors/object/object_modifier.cc
index 523be5eda13..e8da35c25f4 100644
--- a/source/blender/editors/object/object_modifier.cc
+++ b/source/blender/editors/object/object_modifier.cc
@@ -858,25 +858,35 @@ static bool modifier_apply_shape(Main *bmain,
   return true;
 }
 
+static bool meta_data_matches(const std::optional<blender::bke::AttributeMetaData> meta_data,
+                              const eAttrDomainMask domains,
+                              const eCustomDataMask types)
+{
+  if (!meta_data) {
+    return false;
+  }
+  if (!(ATTR_DOMAIN_AS_MASK(meta_data->domain) & domains)) {
+    return false;
+  }
+  if (!(CD_TYPE_AS_MASK(meta_data->data_type) & types)) {
+    return false;
+  }
+  return true;
+}
+
 static void remove_invalid_attribute_strings(Mesh &mesh)
 {
   using namespace blender;
   bke::AttributeAccessor attributes = mesh.attributes();
-  if (mesh.active_color_attribute) {
-    const std::optional<bke::AttributeMetaData> meta_data = attributes.lookup_meta_data(
-        mesh.active_color_attribute);
-    if (!meta_data || !(meta_data->domain & ATTR_DOMAIN_MASK_COLOR) ||
-        !(meta_data->data_type & CD_MASK_COLOR_ALL)) {
-      MEM_SAFE_FREE(mesh.active_color_attribute);
-    }
-  }
-  if (mesh.default_color_attribute) {
-    const std::optional<bke::AttributeMetaData> meta_data = attributes.lookup_meta_data(
-        mesh.default_color_attribute);
-    if (!meta_data || !(meta_data->domain & ATTR_DOMAIN_MASK_COLOR) ||
-        !(meta_data->data_type & CD_MASK_COLOR_ALL)) {
-      MEM_SAFE_FREE(mesh.default_color_attribute);
-    }
+  if (!meta_data_matches(attributes.lookup_meta_data(mesh.active_color_attribute),
+                         ATTR_DOMAIN_MASK_COLOR,
+                         CD_MASK_COLOR_ALL)) {
+    MEM_SAFE_FREE(mesh.active_color_attribute);
+  }
+  if (!meta_data_matches(attributes.lookup_meta_data(mesh.default_color_attribute),
+                         ATTR_DOMAIN_MASK_COLOR,
+                         CD_MASK_COLOR_ALL)) {
+    MEM_SAFE_FREE(mesh.default_color_attribute);
   }
 }



More information about the Bf-blender-cvs mailing list