Skip to content

[p5.js 2.0+ Bug Report]: paletteLerp() returns undefined outside p5.strands #9328

Closed

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

Web browser and version

Chromium

Operating system

Fedora Linux

Steps to reproduce this

A regular paletteLerp() call returns undefined on current main and 2.4.0-rc.1.

For example:

function setup() {
  createCanvas(100, 100);

  const c = paletteLerp(
    [
      [color(255, 0, 0), 0],
      [color(0, 0, 255), 1]
    ],
    0.5
  );

  console.log(c);
  background(c);
}

Expected: c is the interpolated color.

Actual: c is undefined, so the sketch renders black.

This works as expected in 2.3.4 and 1.11.13.

The regression appears to come from the p5.strands override of paletteLerp(): when no Strands context is active, it returns without falling back to the original CPU implementation.

lerpColor() has the expected fallback behavior, and paletteLerp() still works correctly inside Strands on both WebGL and WebGPU.

I couldn't find an existing issue or PR covering this regression.

Activity

  1. LalitNarayanYadav commented on Oct 26, 2026

    @LalitNarayanYadav
    Contributor

    Thanks for the report, @bhabishnu, I can confirm this on current main.

    The override I added in #8817 (src/strands/strands_api.js, for #8751) starts with if (!strandsContext.active) return;, so outside Strands it never reaches the CPU implementation in src/color/creating_reading.js. Unlike lerpColor, red, green, blue and random, it also never saves the original function. The existing tests only call paletteLerp inside Strands, so nothing caught it.

    I'd like to fix this since it came from my change. The plan is to save const originalPaletteLerp = fn.paletteLerp; before the augmentFn call, delegate to it when Strands is inactive, and add a unit test for the non-Strands path. @davepagurek, is it okay if I take this?

  2. davepagurek commented on Oct 26, 2026

    @davepagurek
    Contributor

    Thanks, go ahead!

    Thanks for testing and catching this @bhabishnu!

  3. bhabishnu commented on Oct 27, 2026

    @bhabishnu
    ContributorAuthor

    Sounds good, thanks! Happy to help test the PR once it’s up.

  4. added this to the 2.4 milestone on Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions