Skip to content

Commit

Permalink
fix: Zero derivs for interactive params when needed (#1700)
Browse files Browse the repository at this point in the history
Sometimes an interactive param is used in a way that gets
flagged as needing derivs. But we were neither allocating space
for that nor zeroing them. This resulted on memory corruption.

This fixes incorrect renders in a production context where params are
often tagged as needing derivs.

Signed-off-by: Alejandro Conty <aconty@imageworks.com>
  • Loading branch information
aconty committed Jun 20, 2023
1 parent 5e10537 commit b4f0517
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/liboslexec/runtimeoptimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3283,11 +3283,15 @@ RuntimeOptimizer::run()
// interactive parameter, including correct alignment.
size_t offset = interactive_data.size();
size_t typesize = s.typespec().simpletype().size();
size_t totalsize = typesize * (s.has_derivs() ? 3 : 1);
size_t alignment = typesize > 4 ? 8 : 4;
offset = OIIO::round_to_multiple_of_pow2(offset, alignment);
interactive_data.resize(offset + typesize);
interactive_data.resize(offset + totalsize);
// Copy from the instance value to the interactive block
memcpy(&interactive_data[offset], s.data(), typesize);
if (totalsize > typesize)
memset(&interactive_data[offset] + typesize, 0,
totalsize - typesize);
// Make sure the symbol remembers it's stored in the interactive
// arena with the right offset.
group().add_interactive_param(layer, s.name(), offset);
Expand Down

0 comments on commit b4f0517

Please sign in to comment.