[p5.js 2.0+ Bug Report]: p5.strands overwrites a saved value when the else branch updates the original
Most appropriate sub-area of p5.js?
- [ ] Accessibility
- [ ] Color
- [ ] Core/Environment/Rendering
- [ ] Data
- [ ] DOM
- [ ] Events
- [ ] Image
- [ ] IO
- [ ] Math
- [ ] Typography
- [ ] Utilities
- [x] WebGL
- [ ] WebGPU
- [x] p5.strands
- [ ] Build process
- [ ] Unit testing
- [ ] Internationalization
- [ ] Friendly errors
- [ ] Other (specify if possible)
p5.js version
2.3.2 / main at aa192a2d8
Web browser and version
Chromium (Vitest browser mode; exact version not recorded)
Operating system
Fedora Linux
Steps to reproduce this
In the existing test/unit/webgl/p5.Shader.js harness, render this shader:
myp5.createCanvas(100, 50, myp5.WEBGL);
const testShader = myp5.baseMaterialShader().modify(
() => {
myp5.getPixelInputs(inputs => {
let color = myp5.float(0.2) + inputs.texCoord.x * 0.2;
const saved = color;
if (inputs.texCoord.x > 0.5) {
// Leave color unchanged.
} else {
color = color + 0.3;
}
inputs.color = [saved, color, 0, 1];
return inputs;
});
},
{ myp5 }
);
myp5.noStroke();
myp5.shader(testShader);
myp5.plane(myp5.width, myp5.height);
Check myp5.get(25, 25) and myp5.get(75, 25).
- Left: expected RGB approximately
[64, 140, 0], actual[140, 140, 0]. - Right: expected and actual
[89, 89, 0].
saved should retain its earlier value, but the else branch overwrites it. The generated GLSL uses T0 for both values and outputs vec4(T0, T0, 0, 1).
Reproduced on aa192a2d8. The relevant codegen is unchanged at 93c7ddbb by source comparison; I haven't rerun it there.
Hi @bhabishnu If you are not already working on this issue i would like to take it up. Kindly let me know
Hey @mansi-singh4, thanks for offering! I’ve already prepared and tested a fix locally, and I’m waiting for maintainer feedback before opening a PR.
@bhabishnu feel free to open your PR whenever you're ready. Thanks for catching this.
Thanks! I’ve opened the PR now.