Skip to content

Comments

docs: render.js preload fix#4227

Merged
lmccart merged 1 commit intoprocessing:masterfrom
therewasaguy:p5sound-docs-preload-fix
Jan 3, 2020
Merged

docs: render.js preload fix#4227
lmccart merged 1 commit intoprocessing:masterfrom
therewasaguy:p5sound-docs-preload-fix

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