Skip to content

[p5.js 2.0+ Bug Report]: p5.strands overwrites a saved value when the else branch updates the original #9265

Description

@bhabishnu

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • WebGPU
  • p5.strands
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

2.3.2 / main at aa192a2

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions