diff --git a/src/cmake/testing.cmake b/src/cmake/testing.cmake index 6bc93e924..1f94483a6 100644 --- a/src/cmake/testing.cmake +++ b/src/cmake/testing.cmake @@ -356,7 +356,7 @@ macro (osl_add_all_tests) printf-reg printf-whole-array raytype raytype-reg raytype-specialized regex-reg - reparam reparam-arrays reparam-string testoptix-reparam + reparam reparam-arrays reparam-connected-crash reparam-string testoptix-reparam render-background render-bumptest render-bunny render-cornell diff --git a/src/liboslexec/backendllvm.cpp b/src/liboslexec/backendllvm.cpp index 161ec852a..1a81f84f2 100644 --- a/src/liboslexec/backendllvm.cpp +++ b/src/liboslexec/backendllvm.cpp @@ -232,7 +232,8 @@ BackendLLVM::getLLVMSymbolBase(const Symbol& sym) llvm_type(sym.typespec().elementtype())); return result; } - if (sym.symtype() == SymTypeParam && sym.interactive()) { + if (sym.symtype() == SymTypeParam && sym.interactive() + && !sym.connected()) { // Special case for interactively-edited parameters -- they live in // the interactive data block for the group. // Generate the pointer to this symbol by offsetting into the diff --git a/src/liboslexec/batched_backendllvm.cpp b/src/liboslexec/batched_backendllvm.cpp index 543cbc2cf..2d8b9cd72 100644 --- a/src/liboslexec/batched_backendllvm.cpp +++ b/src/liboslexec/batched_backendllvm.cpp @@ -454,7 +454,8 @@ BatchedBackendLLVM::getLLVMSymbolBase(const Symbol& sym) return result; } - if (sym.symtype() == SymTypeParam && sym.interactive()) { + if (sym.symtype() == SymTypeParam && sym.interactive() + && !sym.connected()) { // Special case for interactively-edited parameters -- they live in // the interactive data block for the group. // Generate the pointer to this symbol by offsetting into the diff --git a/testsuite/reparam-connected-crash/BATCHED b/testsuite/reparam-connected-crash/BATCHED new file mode 100644 index 000000000..e69de29bb diff --git a/testsuite/reparam-connected-crash/downstream.osl b/testsuite/reparam-connected-crash/downstream.osl new file mode 100644 index 000000000..00f222271 --- /dev/null +++ b/testsuite/reparam-connected-crash/downstream.osl @@ -0,0 +1,11 @@ +// Copyright Contributors to the Open Shading Language project. +// SPDX-License-Identifier: BSD-3-Clause +// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage + +// Downstream layer: 'in' will be marked interactive with an instance value +// via testshade -param:interactive=1 +shader downstream(float in = 0, output float result = 0) +{ + printf("in = %g\n", in); + result = in; +} diff --git a/testsuite/reparam-connected-crash/ref/out.txt b/testsuite/reparam-connected-crash/ref/out.txt new file mode 100644 index 000000000..1a43ac53b --- /dev/null +++ b/testsuite/reparam-connected-crash/ref/out.txt @@ -0,0 +1,5 @@ +Compiled downstream.osl -> downstream.oso +Compiled upstream.osl -> upstream.oso +Connect upstream_layer.out to downstream_layer.in +in = 0.5 + diff --git a/testsuite/reparam-connected-crash/run.py b/testsuite/reparam-connected-crash/run.py new file mode 100644 index 000000000..5295ace29 --- /dev/null +++ b/testsuite/reparam-connected-crash/run.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +# Copyright Contributors to the Open Shading Language project. +# SPDX-License-Identifier: BSD-3-Clause +# https://github.com/AcademySoftwareFoundation/OpenShadingLanguage + +# Regression test: downstream input param is both connected (from upstream) and +# marked interactive with an instance value. +# +# Bug: OSL give precedence to the interactive trait instead of connected. This +# leads to an attempted write of the interactive buffer. However, the offset +# is calculated incorrectly and the write occurs at interactive_buffer[-1]. +# +# Correct output: in = 0.5 (u at the default shade point, from the connection) +# Buggy output: in = (corrupted memory) or crash + +command += testshade( + "-layer upstream_layer upstream " + "-layer downstream_layer -param:interactive=1 in 9.0 downstream " + "-connect upstream_layer out downstream_layer in " +) + +outputs = ["out.txt"] diff --git a/testsuite/reparam-connected-crash/upstream.osl b/testsuite/reparam-connected-crash/upstream.osl new file mode 100644 index 000000000..c50e75225 --- /dev/null +++ b/testsuite/reparam-connected-crash/upstream.osl @@ -0,0 +1,8 @@ +// Copyright Contributors to the Open Shading Language project. +// SPDX-License-Identifier: BSD-3-Clause +// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage + +shader upstream(output float out = 0) +{ + out = u; // don't constant-fold +}