Skip to content

[p5.js 2.0 Bug Report]: Can't recover from a p5.strands error #8300

@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.x

Web browser and version

All

Operating system

All

Steps to reproduce this

Steps:

  1. Inside a try/catch, initialize a p5.strands shader, but make a typo in your code to cause an error
  2. Try to draw something afterwards using a function p5.strands overrides, like noise

Those functions won't work even after catching the error. This is because the strands context is still active and is never cleaned up, so your only real option is to reload the page. This is a problem in contexts where you're making an editor of sorts that uses p5, and user input may contain errors.

Snippet:

let sh
function setup() {
  createCanvas(400, 400, WEBGL);
  
  try {
    sh = baseFilterShader().modify(() => {
      getColor(() => {
        thisVariableIsUndefined.something()
      })
    })
  } catch (e) {
    console.log(e)
  }
}

function draw() {  
  background('red')
  circle(100 * noise(frameCount * 0.1), 100 * noise(frameCount * 0.1), 20)
}

Live: https://editor.p5js.org/davepagurek/sketches/3R8dqaSIS

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions