diff options
author | Jacques Lucke <jacques@blender.org> | 2021-01-21 18:55:44 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-01-21 19:02:07 +0300 |
commit | ceb500df0384dee3bda07f10a0a93acf40ac25c9 (patch) | |
tree | 2dbe751674e938494224435a12ba30359dbaf2ca | |
parent | 3fd92b5c224b4a5ba274514a62643f8d7df644d9 (diff) |
Geometry Nodes: fix losing data when attribute has incorrect type
Differential Revision: https://developer.blender.org/D10165
-rw-r--r-- | source/blender/blenkernel/intern/attribute_access.cc | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc index 2e1094364fd..e1e8d06b9ec 100644 --- a/source/blender/blenkernel/intern/attribute_access.cc +++ b/source/blender/blenkernel/intern/attribute_access.cc @@ -862,10 +862,19 @@ OutputAttributePtr::OutputAttributePtr(GeometryComponent &component, const int domain_size = component.attribute_domain_size(domain); void *buffer = MEM_malloc_arrayN(domain_size, cpp_type->size(), __func__); - cpp_type->construct_default_n(buffer, domain_size); + GMutableSpan new_span{*cpp_type, buffer, domain_size}; + + /* Copy converted values from conflicting attribute, in case the value is read. + * TODO: An optimization could be to not do this, when the caller says that the attribute will + * only be written. */ + ReadAttributePtr src_attribute = component.attribute_get_for_read( + final_name, domain, data_type, nullptr); + for (const int i : blender::IndexRange(domain_size)) { + src_attribute->get(i, new_span[i]); + } attribute_ = std::make_unique<blender::bke::TemporaryWriteAttribute>( - domain, GMutableSpan{*cpp_type, buffer, domain_size}, component, std::move(final_name)); + domain, new_span, component, std::move(final_name)); } /* Store the computed attribute. If it was stored from the beginning already, nothing is done. This |