Many modifiers and other places use CustomData_copy_data to copy data between different meshes. This function assumes that assumes that the source and destination CustomData objects are "compatible" in some way. Usually modifiers use CustomData_copy to create a compatible new CustomData on the new mesh. The issue was that the optimization I added for anonymous attributes broke this compatibility. It avoided copying some attributes when they are no longer used.
This lead to attributes being copied incorrectly.
The real solution would be to not depend on this kind of compatibility in CustomData_copy_data. However, changing that in a way that does not cause significant performance regressions in other parts of Blender is too risky for 3.0 (the issue is that CustomData_copy_data is often called for single elements, we don't want to compare all attribute names for all elements). Possible solutions for the future are:
- Preprocess the mapping between two CustomData so that corresponding layers don't have to be found for every element.
- Separate computing which indices are copied to which other indices from actually copying the data. Once the index mapping (e.g. in form of an integer array) is generated, one can process the CustomData layer by layer, reducing overhead significantly.
For now I just removed the optimization.
The viewer node had an affect on the behavior, because when the geometry was viewed, the captured anonymous attribute was still needed and therefore wasn't removed.