Fix #113011: Leak of Anonymous Attributes #113053

Merged
Jacques Lucke merged 5 commits from mod_moder/blender:fix_att_leak into blender-v4.0-release 2023-09-29 21:23:24 +02:00
Showing only changes of commit 40b5e683a6 - Show all commits

View File

@ -123,19 +123,27 @@ static void clean_unused_attributes(const AnonymousAttributePropagationInfo &pro
GeometryComponent &component)
{
std::optional<MutableAttributeAccessor> attributes = component.attributes_for_write();
const Set<AttributeIDRef> all_ids = attributes.has_value() ? attributes->all_ids() :
Set<AttributeIDRef>();
for (const AttributeIDRef &id : all_ids) {
if (!attributes.has_value()) {
return;
}
Vector<std::string> unused_ids;
attributes->for_all([&](const AttributeIDRef &id, const AttributeMetaData /*meta_data*/) {
if (!id.is_anonymous()) {
continue;
return true;
}
if (skip.contains(id)) {
continue;
return true;
}
if (propagation_info.propagate(id.anonymous_id())) {
mod_moder marked this conversation as resolved Outdated

Might need to be careful here, removing an attribute may invalidate data referenced by other AttributeIDRef (mainly the name). Better first gather the names of all attributes to remove, store them as std::string and then remove them in a second loop.

Might need to be careful here, removing an attribute may invalidate data referenced by other `AttributeIDRef` (mainly the name). Better first gather the names of all attributes to remove, store them as `std::string` and then remove them in a second loop.
continue;
return true;
}
attributes->remove(id);
unused_ids.append(id.name());
return true;
});
for (const std::string &unused_id : unused_ids) {
attributes->remove(unused_id);
}
}