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

Instance mode not working #21

Closed
rmtrmt opened this issue Feb 2, 2024 · 2 comments
Closed

Instance mode not working #21

rmtrmt opened this issue Feb 2, 2024 · 2 comments

Comments

@rmtrmt
Copy link

rmtrmt commented Feb 2, 2024

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

@acamposuribe
Copy link
Owner

acamposuribe commented Feb 2, 2024

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);
      ```

@rmtrmt
Copy link
Author

rmtrmt commented Feb 2, 2024

That works, thanks!

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

No branches or pull requests

2 participants