AcademySoftwareFoundation / AcademySoftwareFoundation/OpenShadingLanguage
structs of structs don't seem to work
- Dominant language
- C++
- Stars
- 2.3k
- Forks
- 414
- Avg merge
- 3d 1h
- Merged PRs (30d)
- 10
Description
**Describe the bug**
Adding a struct to a struct seems to result in undefined initialization behavior.
**OSL version and dependencies**
* OSL branch/version: 1.13.12.0.2
* OS: Rocky Linux release 9.4
* C++ compiler: clang-15.0.7.3
* LLVM version: llvm-15.0.7.1
* OIIO version: OpenImageIO-2.4.13.0.4
* Qt version: Qt-5.15.3.8
**To Reproduce**
Steps to reproduce the behavior:
Given the following structs:
```
struct StructA
{
float cellRand;
point minDist;
point closest;
point secondClosest;
float edgeDist;
};
struct StructB
{
StructA result;
int level;
float scale;
};
```
and given a shading function with signature:
`StructA somefunction();`
If you try and initialize using:
`StructB value = StructB(somefunction(), 0, 1.0);`
all the attributes are correctly set in the various structs, but if, instead, you do:
```
StructA temp = somefunction();
StructB value = StructB(temp, 0, 1.0);
```
then value is incorrect, and the result member is filled with zeroes.
**Evidence**
- I was trying to assemble a full test example using osltoy, but was blocked by: https://github.com/AcademySoftwareFoundation/OpenShadingLanguage/issues/2035
It'd be great for someone else to confirm they can reproduce this behavior, thanks!
Contributor guide
Research direction
Start by reproducing the shown StructA and StructB initialization cases with the reported OSL 1.13.12.0.2 environment. The reporter mentions using osltoy but was blocked by issue 2035; confirm whether the temporary-variable case still produces zeroes and identify the relevant compiler or code-generation path before defining the fix.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100