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.
This commit is contained in:
Hans Goudey 2022-09-21 12:06:53 -05:00
parent c1f622e63e
commit a82e52102b
2 changed files with 8 additions and 6 deletions

View File

@ -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,

View File

@ -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;