Skip to content

[p5.js 2.0+ Bug Report]: p5.strands loop-carried variables can read values overwritten earlier in the same iteration #9377

Open

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.4.0-rc.5

Web browser and version

Google Chrome 152

Operating system

Fedora Linux

Steps to reproduce this

Steps

  1. Use two loop-carried values inside a p5.strands hook.
  2. Swap them inside a for loop.
  3. Use the result for the output color.
filterColor.begin();

let a = 0.25;
let b = 0.75;

for (let i = 0; i < 1; i++) {
  const t = a;
  a = b;
  b = t;
}

filterColor.set([a, b, 0, 1]);
filterColor.end();

Expected

a = 0.75
b = 0.25

roughly [191, 64, 0].

Actual

a = 0.75
b = 0.75

roughly [191, 191, 0], with no error.

I can reproduce the same ordering issue with rotations and Fibonacci-style updates. It happens on WebGL and WebGPU on 2.4.0-rc.5, current main (8831d5baf), and 2.3.4.

The ordering is already present before backend-specific code generation, so this seems to be in the loop-carried state handling.

I'd be happy to work on a fix if this is confirmed.

Activity

  1. bhabishnu commented on Nov 8, 2026

    @bhabishnu
    ContributorAuthor

    hey @davepagurek, looks like @Pcmhacker-hero has opened #9383 before assignment again, similar to what happened on #9327. could you clarify who should take this one?

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