Most appropriate sub-area of p5.js?
p5.js version
main (aa192a2; package version 2.3.2)
Web browser and version
Chromium (Vitest; browser version not recorded)
Operating system
Fedora Linux
Steps to reproduce this
Updating inputs.color.rgb inside a Strands for loop throws during shader construction. The same loop works when it updates a local colour variable and assigns it to inputs.color afterward.
Add this beside handle swizzle assignments in loops in test/unit/webgl/p5.Shader.js:
test('handle swizzle assignments on hook color in loops', () => {
myp5.createCanvas(50, 50, myp5.WEBGL);
const testShader = myp5.baseMaterialShader().modify(
() => {
myp5.getPixelInputs(inputs => {
inputs.color = [0, 0, 0, 1];
for (let i = 0; i < 3; i++) {
inputs.color.rgb += 0.1;
}
return inputs;
});
},
{ myp5 }
);
myp5.noStroke();
myp5.shader(testShader);
myp5.plane(myp5.width, myp5.height);
const pixelColor = myp5.get(25, 25);
assert.approximately(pixelColor[0], 77, 5);
assert.approximately(pixelColor[1], 77, 5);
assert.approximately(pixelColor[2], 77, 5);
});
Run:
npx vitest run --project unit-tests --reporter=default test/unit/webgl/p5.Shader.js -t "handle swizzle assignments (in loops|on hook color in loops)"
Expected behavior
Both tests should pass, producing RGB values approximately 77.
Actual behavior
The existing local-variable test passes. The hook-property test throws:
TypeError: Cannot read properties of undefined (reading 'color')
❯ StrandsFor.executeBodyCallback src/strands/strands_for.js:490:29
Additional context
Source inspection suggests the loop stores state under 'inputs.color' but reads it as vars.inputs.color.
Found while investigating #9259. This concerns explicit property updates, separate from the proposed implicit addon-state handling.
Most appropriate sub-area of p5.js?
p5.js version
main (aa192a2; package version 2.3.2)
Web browser and version
Chromium (Vitest; browser version not recorded)
Operating system
Fedora Linux
Steps to reproduce this
Updating
inputs.color.rgbinside a Strandsforloop throws during shader construction. The same loop works when it updates a local colour variable and assigns it toinputs.colorafterward.Add this beside
handle swizzle assignments in loopsintest/unit/webgl/p5.Shader.js:Run:
npx vitest run --project unit-tests --reporter=default test/unit/webgl/p5.Shader.js -t "handle swizzle assignments (in loops|on hook color in loops)"Expected behavior
Both tests should pass, producing RGB values approximately 77.
Actual behavior
The existing local-variable test passes. The hook-property test throws:
Additional context
Source inspection suggests the loop stores state under
'inputs.color'but reads it asvars.inputs.color.Found while investigating #9259. This concerns explicit property updates, separate from the proposed implicit addon-state handling.