Page MenuHome

Fix T90026: attributes added in editmode are lost on modeswitch
ClosedPublic

Authored by Philipp Oeser (lichtwerk) on Jul 22 2021, 2:11 PM.

Details

Summary

When exiting editmode, customdata [and thus attributes] are copied from
BMesh to Mesh (in BM_mesh_bm_to_me).
When adding attributes, these were always added via
CustomData_add_layer_named only.
Instead (if we are in mesh editmode), we need to go through
BM_data_layer_add_named to properly update the BMesh (see
update_data_blocks) so we have stuff available to copy back to
Mesh when exiting editmode.

This is now done, DomainInfo is updated to point to BMesh (instead of
Mesh) customdata when in editmode.

Diff Detail

Repository
rB Blender

Event Timeline

Philipp Oeser (lichtwerk) requested review of this revision.Jul 22 2021, 2:11 PM
Philipp Oeser (lichtwerk) created this revision.
Brecht Van Lommel (brecht) requested changes to this revision.Jul 22 2021, 2:53 PM

A consequence of this is that attribute.data will be empty when in edit mode, since custom data is stored per element instead of a single array there. UV maps behave the same so that seems fine.

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

Always add a break statement. In this case a simple if/else is enough though, not need for a switch.

186

Removal likely needs similar change to use BM_data_layer_free?

This revision now requires changes to proceed.Jul 22 2021, 2:53 PM
  • avoid fallthrough (add missing break)
  • go through BMesh for removal as well
  • add a check for totlayers (otherwise iter is in eternal loop -- bit on shaky ground here tbh.)
Philipp Oeser (lichtwerk) marked 2 inline comments as done.Jul 22 2021, 5:23 PM

A consequence of this is that attribute.data will be empty when in edit mode, since custom data is stored per element instead of a single array there. UV maps behave the same so that seems fine.

Hm, yes, same is true at least for vertexcolors as well though.
Also: I am a bit on shaky ground in regards to the iterators still doing what they should in editmode (see that additional customdata->totlayer check -- for some reason this was neccessary for removing edge attributes that were added in editmode, customdata->layers was valid, but had totlayer of zero?)

Looks good to me now.

This revision is now accepted and ready to land.Jul 22 2021, 5:37 PM