diff options
author | Jacques Lucke <jacques@blender.org> | 2022-04-21 16:29:07 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2022-04-21 16:29:18 +0300 |
commit | c196ca37407d4dacb832d4c888ac87e66d7094c5 (patch) | |
tree | 1e9617668055d5d94163c9d31845be6d3b47a590 /source/blender/functions/tests/FN_multi_function_procedure_test.cc | |
parent | 0178e694b72d32ee9805b2f854d1dc4cc46d481f (diff) |
Functions: fix procedure executor not writing output in correct buffer
The issue was that the executor would forget about the caller provided
storage if the variable is destructed.
Diffstat (limited to 'source/blender/functions/tests/FN_multi_function_procedure_test.cc')
-rw-r--r-- | source/blender/functions/tests/FN_multi_function_procedure_test.cc | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/source/blender/functions/tests/FN_multi_function_procedure_test.cc b/source/blender/functions/tests/FN_multi_function_procedure_test.cc index a196d0396ec..e7cedb40f83 100644 --- a/source/blender/functions/tests/FN_multi_function_procedure_test.cc +++ b/source/blender/functions/tests/FN_multi_function_procedure_test.cc @@ -378,4 +378,34 @@ TEST(multi_function_procedure, BufferReuse) EXPECT_EQ(results[4], 53); } +TEST(multi_function_procedure, OutputBufferReplaced) +{ + MFProcedure procedure; + MFProcedureBuilder builder{procedure}; + + const int output_value = 42; + CustomMF_GenericConstant constant_fn(CPPType::get<int>(), &output_value, false); + MFVariable &var_o = procedure.new_variable(MFDataType::ForSingle<int>()); + builder.add_output_parameter(var_o); + builder.add_call_with_all_variables(constant_fn, {&var_o}); + builder.add_destruct(var_o); + builder.add_call_with_all_variables(constant_fn, {&var_o}); + builder.add_return(); + + EXPECT_TRUE(procedure.validate()); + + MFProcedureExecutor procedure_fn{procedure}; + + Array<int> output(3, 0); + fn::MFParamsBuilder params(procedure_fn, output.size()); + params.add_uninitialized_single_output(output.as_mutable_span()); + + fn::MFContextBuilder context; + procedure_fn.call(IndexMask(output.size()), params, context); + + EXPECT_EQ(output[0], output_value); + EXPECT_EQ(output[1], output_value); + EXPECT_EQ(output[2], output_value); +} + } // namespace blender::fn::tests |