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

If a function prints an object with p5.Graphics object, the function won't print anything else #3330

Open
VinkentLi opened this issue Feb 1, 2025 · 5 comments
Labels

Comments

@VinkentLi
Copy link

p5.js version

1.11.1

What is your operating system?

Windows

Web browser and version

Chrome version: 132.0.6834.160

Actual Behavior

The program doesn't log anything, even though draw() calls console.log();

Expected Behavior

The program should log "test" and the obj object every frame.

Steps to reproduce

Steps:

  1. Create object with p5.Graphics object
  2. Try to print something in a function along with the object

Snippet:

let obj = {graphics: null};

function setup() {
  createCanvas(400, 400);
  obj.graphics = createGraphics(400, 400);
}

function draw() {
  background(220);
  console.log("test");
  console.log(obj);
}
@VinkentLi VinkentLi added the Bug label Feb 1, 2025
Copy link

welcome bot commented Feb 1, 2025

Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, be sure to follow the issue template if you haven't already.

@KamakshiBali
Copy link
Contributor

Are you talking about the browser's console or the in-built console in p5.js, because it does log the output in the former.

@VinkentLi
Copy link
Author

The built-in console in the p5js editor

@KamakshiBali
Copy link
Contributor

I think the built-in console doesnt support complex objects like p5.Graphics, so it might fail to stringify it because of which nothing appears.

And in the browser console too, it does log the output but after sometime it starts giving Maximum call stack size exceeded error, so there's a recursion issue possibly because Immer.js may not be able to handle non-serializable objects like p5.Graphics

@KamakshiBali
Copy link
Contributor

console.log(JSON.stringify({ width: obj.graphics.width, height: obj.graphics.height }));
this line logs the output in the built-in console.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants