Skip to content

P5 instance mode issues #35

@jamesrweb

Description

@jamesrweb

When writing instance mode integrations using @p5-wrapper/react or other libraries, it is not possible to rely on global p5 and yet it seems there is a reliance on it existing even on the p5-instance-mode example in this project.

Here is some example code I would like to be able to write:

import { P5Capture } from "p5.capture"

export function sketch(p5) {
    const capture = new P5Capture(p5);

    p5.setup = () => {
        p5.createCanvas(300, 300);
    }

    p5.draw = () => {
        if (p5.frameCount === 1) {
            const capture = capture.getInstance();
            capture.start({
                format: "gif",
                duration: 100,
            });
        }
    }

    p5.keyPressed = () => {
        if (key === "c") {
            const capture = capture.getInstance();

            if (capture.state === "idle") {
                capture.start();
            } else {
                capture.stop();
            }
        }
    }
}

But even when attempting with import "p5.capture" and P5Capture.initialize(p5) or even p5.capture.{initialize/start/stop} and all options throw the same error, implying it is a bootstrapping issue relying on global p5 which specifically states:

Uncaught ReferenceError: p5 is not defined

Which is thrown on the check for if (p5.registerAddon) ... and seems to originate on this line and this seems to be the only place this check is made.

How can we do proper instance mode integrations?
Am I missing something p5.capture specific?
Or am I misunderstanding the documentation?

I would like instance mode to be supported properly either way as some users have asked for this integration with p5.capture and I am not sure how exactly to go about it when the above error is consistent across all options attempted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions