Skip to content

[p5.js 2.0+ Bug Report]: NaN in Vertex #9320

Open

Description

@lewi0622

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

No response

Operating system

No response

Steps to reproduce this

Steps:

In V2, giving a NaN value in a vertex call will create a point at 0,0, and throw a warning.

While the warning is nice (in V1, there was no warning!) I don't think we should draw a point at 0,0. I don't think we can assume a NaN means 0, and in the example code below, it ignores the value of y=height/4 and creates a point at y=0, which is strange behavior.

I don't think we should draw a point with a NaN in the vertex call at all, which is what happened in V1, the point was just ignored. Or, we could throw a runtime error instead of just a warning. If I'm not peeking at the console, I would love to know when my code is accidentally generating a NaN so I can track that problem down.

Snippet:

https://editor.p5js.org/lewi0622/sketches/o6_x-akX1

  translate(width/2, height/2);
  beginShape();
  vertex(width/4, height/4);
  vertex(0, height/4);
  //When vertex recieves a NaN for one of the values, it sets both values to 0 and draws the point and gives a warning
  vertex(NaN, -height/4);
  endShape();

Activity

  1. welcome commented on Oct 22, 2026

    @welcome

    Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, please make sure to fill out the inputs in the issue forms.

    For guidance on contributing, check out our contributing guidelines and other resources for contributors.
    💬 If you have questions or need support, feel free to join the Processing Foundation Forum or visit our Community page.
    📜 Please also review our Code of Conduct to understand our community standards.
    Thank You!

  2. Anshumancanrock commented on Oct 24, 2026

    @Anshumancanrock
    Contributor

    Hi @ksen0 , I can reproduce this on 2.3.4 and 2.4.0-rc.1, in both 2D and WEBGL.

    It looks like it comes from the p5.Vector constructor. If any argument is non-finite it sets values = [], and the x/y/z getters fall back to 0, so the whole vertex ends up at (0, 0) and the valid y is lost. On 2.2.3 only the NaN coordinate became 0, and in 1.x (2D) the point was skipped. line() and point() with NaN do the same thing, and with p5.min.js there's no warning at all.

    Which behavior would you prefer here: skipping the vertex like 1.x, going back to the 2.2 behavior, or throwing an error like the issue suggests? I'd like to work on it once there's a direction.

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