Skip to content

[p5.js 2.0 Bug Report]: p5.strands callbacks don't work with inline anonymous non-arrow functions #7955

@davepagurek

Description

@davepagurek

Most appropriate sub-area of p5.js?

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

p5.js version

2.0.3

Web browser and version

Firefox

Operating system

MacOS

Steps to reproduce this

Steps:

  1. Take a p5.strands example (e.g. the first on here: https://beta.p5js.org/reference/p5/basematerialshader/)
  2. Change the arrow function to a function() { ... }

The code stops working.

Snippet:

let myShader;

function setup() {
  createCanvas(200, 200, WEBGL);
  // Works:
  // myShader = baseMaterialShader().modify(() => {
  
  // Doesn't work:
  myShader = baseMaterialShader().modify(function() {
    let time = uniformFloat(() => millis());
    getWorldInputs((inputs) => {
      inputs.position.y +=
        20 * sin(time * 0.001 + inputs.position.x * 0.05);
      return inputs;
    });
  });
}

function draw() {
  background(255);
  shader(myShader);
  lights();
  noStroke();
  fill('red');
  sphere(50);
}

Live: https://editor.p5js.org/davepagurek/sketches/Xla02SjFQ

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions