Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: render.js preload fix #4227

Merged
merged 1 commit into from
Jan 3, 2020

Conversation

therewasaguy
Copy link
Member

Same as processing/p5.js-website#524 by @oshoham, which unblocks #3988

This applies the same fix to the render.js file that lives in this repo.

The most recent version of p5.sound uses the p5.js preload system to asynchronously load AudioWorklet modules before a sketch runs. In order to ensure that the preload system is always invoked, p5.sound adds an empty preload function to a p5.js sketch if one doesn't already exist. For more details on this, see the p5.sound repo.

This created a conflict with the render.js script used to display reference examples, which looks for lifecycle methods like setup() and preload() and hoists them if they exists, and otherwise wraps the example code in a setup() function.

Specifically, the presence of a preload key on the p5 instance object p causes an error because render.js incorrectly assumes that every p5.sound reference sketch contains a preload() function and attempts to eval() that function, which throws an error if there isn't a preload() function.

As a workaround, I've added some code that deletes the empty preload() function from the p5 instance object before calling eval() on the reference sketch code, and then adds it back afterwards if the sketch in question doesn't have its own preload() function.

PR Checklist

  • npm run lint passes
  • [Inline documentation] is included / updated

@lmccart lmccart merged commit 99bbd67 into processing:master Jan 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants