xxxxxxxxxx
43
// p5 web editor v2.7.0 introduced a bug
// that causes the page to crash anytime a function throws an error
// this is a temporary workaround until that bug is fixed
function safeSetup() {
// put your normal setup() code here:
createCanvas(400, 400);
}
function safeDraw() {
// put your normal draw() code here:
background(200);
}
// put your setup() code in safeSetup() instead
function setup() {
// calls your code in safeSetup() function
// but if it errors ends the program and logs the error to the console
// once the p5 editor bug is fixed, this try/catch block can be removed
try {
safeSetup();
} catch (e) {
noLoop();
console.error('Error in setup():')
console.error(e);
}
}
// put your draw() code in safeDraw() instead
function draw() {
// calls your code in safeDraw() function
// but if it errors ends the program and logs the error to the console
// once the p5 editor bug is fixed, this try/catch block can be removed
try {
safeDraw();
} catch (e) {
noLoop();
console.error('Error in draw():')
console.error(e);
}
}