[Bf-blender-cvs] [5179b8236ba] master: Fix accessing attribute data in editmode

Philipp Oeser noreply at git.blender.org
Fri Apr 22 15:26:58 CEST 2022


Commit: 5179b8236ba84e50d26485a17df6b17d8e581477
Author: Philipp Oeser
Date:   Thu Apr 21 12:39:09 2022 +0200
Branches: master
https://developer.blender.org/rB5179b8236ba84e50d26485a17df6b17d8e581477

Fix accessing attribute data in editmode

When in mesh editmode, attributes point to bmesh customdata, the
attribute data is empty since custom data is stored per element instead
of a single array there (same es UVs etc.).
Opposed to e.g. UVs, general attributes were not setting their data
length/size to zero in case of editmode though, which could lead to
- crash in Outliner Data Api view [that was reported in T95922]
- RuntimeError such as the following:
```
RuntimeError: bpy_prop_collection[index]: internal error, valid index 0
given in 8 sized collection, but value not found
```

Now check for mesh editmode in `BKE_id_attribute_data_length` (and
return zero in that case).
Alternatively, the check could also be done in
`rna_Attribute_data_length` only (such as UVs do in
`rna_MeshUVLoopLayer_data_length`).

Ref D11998
Fixes T95922

Maniphest Tasks: T95922

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

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

M	source/blender/blenkernel/intern/attribute.c

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

diff --git a/source/blender/blenkernel/intern/attribute.c b/source/blender/blenkernel/intern/attribute.c
index 9b8ae4b3804..0cb0704ff80 100644
--- a/source/blender/blenkernel/intern/attribute.c
+++ b/source/blender/blenkernel/intern/attribute.c
@@ -311,6 +311,20 @@ AttributeDomain BKE_id_attribute_domain(const ID *id, const CustomDataLayer *lay
 
 int BKE_id_attribute_data_length(ID *id, CustomDataLayer *layer)
 {
+  /* When in mesh editmode, attributes point to bmesh customdata layers, the attribute data is
+   * empty since custom data is stored per element instead of a single array there (same es UVs
+   * etc.), see D11998. */
+  switch (GS(id->name)) {
+    case ID_ME: {
+      Mesh *mesh = (Mesh *)id;
+      if (mesh->edit_mesh != NULL) {
+        return 0;
+      }
+    }
+    default:
+      break;
+  }
+
   DomainInfo info[ATTR_DOMAIN_NUM];
   get_domains(id, info);



More information about the Bf-blender-cvs mailing list