Instance mode not working
rmtrmt opened this issue · comments
Russ commented
I'm using the version at 1b7fedd08cf9fd92faf56d97e2496a07e63b99b8
. When I try to use instance mode following the README I get this error
p5.min.js:2 Uncaught TypeError: Cannot read properties of undefined (reading 'push')
at y (p5.brush.js:1:14460)
at Object.blend (p5.brush.js:1:5053)
at g.<anonymous> (p5.brush.js:1:14647)
at g.callRegisteredHooksFor (p5.min.js:2:460507)
at g._setup (p5.min.js:2:463068)
at g._start (p5.min.js:2:461250)
I also get this error when using v1.1.1 from the cdn.
For reference, this is what my script looks like.
let sketch = function (p) {
let x = 100;
let y = 100;
// Register instance method here, sending your function arg p
brush.instance(p);
p.setup = function () {
p.createCanvas(700, 410);
};
p.draw = function () {
p.background(0);
brush.fill("red", 75);
brush.rect(x, y, 50, 50);
};
};
let myp5 = new p5(sketch);
Thanks for taking a look
Alejandro commented
Hi @rmtrmt !
Apologies, it was a problem with the docs.
You need to create the canvas in WEBGL mode, and load the library after that.
In any case, I'm going to push an update soon in order to avoid the loading step, making it more intuitive.
let sketch = function(p) {
let x = 100;
let y = 100;
// Register instance method here, sending your function arg p
brush.instance(p)
p.setup = function() {
// Important to create the canvas in WEBGL mode
p.createCanvas(700, 410, p.WEBGL);
// Don't forget to load the library after canvas is created
brush.load()
};
p.draw = function() {
p.background(0);
brush.fill("red", 75);
brush.rect(x, y, 50, 50);
};
};
let myp5 = new p5(sketch);
```
Russ commented
That works, thanks!