[Bf-blender-cvs] [a82e52102b0] master: Mesh: Avoid uninitialized values when converting BMesh to Mesh

Hans Goudey noreply at git.blender.org
Wed Sep 21 20:10:57 CEST 2022


Commit: a82e52102b0f7ddfe3741fccdaa9de5f480c59fe
Author: Hans Goudey
Date:   Wed Sep 21 12:06:53 2022 -0500
Branches: master
https://developer.blender.org/rBa82e52102b0f7ddfe3741fccdaa9de5f480c59fe

Mesh: Avoid uninitialized values when converting BMesh to Mesh

I didn't observe this issue in practice, but since the write_only
version of the attribute API isn't meant to initialize trivial types,
theoretically this could be a problem if the attribute is created
halfway through converting the BMesh to a Mesh.

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

M	source/blender/blenkernel/BKE_attribute.hh
M	source/blender/bmesh/intern/bmesh_mesh_convert.cc

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

diff --git a/source/blender/blenkernel/BKE_attribute.hh b/source/blender/blenkernel/BKE_attribute.hh
index 946a7d21580..b1f4039f788 100644
--- a/source/blender/blenkernel/BKE_attribute.hh
+++ b/source/blender/blenkernel/BKE_attribute.hh
@@ -692,6 +692,8 @@ class MutableAttributeAccessor : public AttributeAccessor {
    * The "only" in the name indicates that the caller should not read existing values from the
    * span. If the attribute is not stored as span internally, the existing values won't be copied
    * over to the span.
+   *
+   * For trivial types, the values in a newly created attribute will not be initialized.
    */
   GSpanAttributeWriter lookup_or_add_for_write_only_span(const AttributeIDRef &attribute_id,
                                                          const eAttrDomain domain,
diff --git a/source/blender/bmesh/intern/bmesh_mesh_convert.cc b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
index aa8972f9d14..6f1552e6a0f 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_convert.cc
+++ b/source/blender/bmesh/intern/bmesh_mesh_convert.cc
@@ -1279,7 +1279,7 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks *
     mv->flag = BM_vert_flag_to_mflag(eve);
     if (BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
       if (!hide_vert_attribute) {
-        hide_vert_attribute = mesh_attributes.lookup_or_add_for_write_only_span<bool>(
+        hide_vert_attribute = mesh_attributes.lookup_or_add_for_write_span<bool>(
             ".hide_vert", ATTR_DOMAIN_POINT);
       }
       hide_vert_attribute.span[i] = true;
@@ -1301,8 +1301,8 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks *
     med->flag = BM_edge_flag_to_mflag(eed);
     if (BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
       if (!hide_edge_attribute) {
-        hide_edge_attribute = mesh_attributes.lookup_or_add_for_write_only_span<bool>(
-            ".hide_edge", ATTR_DOMAIN_EDGE);
+        hide_edge_attribute = mesh_attributes.lookup_or_add_for_write_span<bool>(".hide_edge",
+                                                                                 ATTR_DOMAIN_EDGE);
       }
       hide_edge_attribute.span[i] = true;
     }
@@ -1337,8 +1337,8 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks *
     mp->flag = BM_face_flag_to_mflag(efa);
     if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
       if (!hide_poly_attribute) {
-        hide_poly_attribute = mesh_attributes.lookup_or_add_for_write_only_span<bool>(
-            ".hide_poly", ATTR_DOMAIN_FACE);
+        hide_poly_attribute = mesh_attributes.lookup_or_add_for_write_span<bool>(".hide_poly",
+                                                                                 ATTR_DOMAIN_FACE);
       }
       hide_poly_attribute.span[i] = true;
     }
@@ -1346,7 +1346,7 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks *
     mp->loopstart = j;
     if (efa->mat_nr != 0) {
       if (!material_index_attribute) {
-        material_index_attribute = mesh_attributes.lookup_or_add_for_write_only_span<int>(
+        material_index_attribute = mesh_attributes.lookup_or_add_for_write_span<int>(
             "material_index", ATTR_DOMAIN_FACE);
       }
       material_index_attribute.span[i] = efa->mat_nr;



More information about the Bf-blender-cvs mailing list