From ceb500df0384dee3bda07f10a0a93acf40ac25c9 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Thu, 21 Jan 2021 16:55:44 +0100 Subject: Geometry Nodes: fix losing data when attribute has incorrect type Differential Revision: https://developer.blender.org/D10165 --- source/blender/blenkernel/intern/attribute_access.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'source/blender/blenkernel') 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( - 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 -- cgit v1.2.3