Skip to content

[p5.js 2.0+ Bug Report]: Compilation bug with strands for loops #9325

Closed

Description

@davepagurek

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.4

Web browser and version

Firefox, Chrome

Operating system

MacOS

Steps to reproduce this

I made this voronoi shader: https://editor.p5js.org/davepagurek/sketches/-0VqoCsyd

let voronoiShader;
function setup() {
  createCanvas(500, 500, WEBGL);
  voronoiShader = buildFilterShader(voronoi);
  console.log(voronoiShader.fragSrc());
}

function voronoi() {
  filterColor.begin();
  let minDist = 1000;
  let minIndex = -1;
  let t = millis() * 0.0001;
  for (let i = 0; i < 5; i++) {
    let cellCoord = [noise(i, 0, t), noise(i, 100, t)];
    let d = length(cellCoord - filterColor.texCoord);
    if (d < minDist) {
      minDist = d;
      minIndex = i;
    }
  }
  let outColor = [
    noise(minIndex, 0),
    noise(minIndex, 100),
    noise(minIndex, 200),
    1,
  ];
  filterColor.set(outColor);
  filterColor.end();
}

function draw() {
  background(0);
  filter(voronoiShader);
}

It seems to crash the GPU context in both firefox and chrome. When I log the GLSL it transpiles to, I see that this part:

if (d < minDist) {
      minDist = d;
      minIndex = i;
    }

becomes this:

if (T5 < T2)
    {
    }
    else
    {
      T5 = T2;
      T3 = T0;
    }
    T2 = T5;
    T0 = T3;

which is not the right structure, and also kinda backwards. If I manually copy and paste the transpiled glsl and correct this, it works as expected: https://editor.p5js.org/davepagurek/sketches/JKRthtPRL

Let me know if someone knows what's up!

Activity

  1. davepagurek commented on Oct 24, 2026

    @davepagurek
    ContributorAuthor

    Never mind this is already fixed on the main branch!

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