Skip to content

Conversation

@Homaid
Copy link

@Homaid Homaid commented Oct 28, 2025

Resolves #8209

Changes:

added a Friendly Error System (FES) warning to detect unmatched push() and pop() calls that can cause performance degradation and browser freezing.

What was added:

  • Warning when push() is called more than 100 times without matching pop() calls within a frame
  • Warning when pop() is called more times than push()
  • Warnings are shown only once per sketch run to avoid console spam
  • Uses the FES system for consistency with other p5.js error messages

Screenshots of the change:

Screenshot 2025-10-28 161055

PR Checklist

@Homaid
Copy link
Author

Homaid commented Oct 28, 2025

Hii @davepagurek can you review this and let me know if anything needs to change thank you!!

Copy link
Collaborator

@perminder-17 perminder-17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, in the screenshot when there's a loop of 100 push() calls without pop() calls, the friendly error message is showing something around 200. Is that expected? or it's something like showing the unmatched stack depth?

@Homaid
Copy link
Author

Homaid commented Oct 29, 2025

Hii @perminder-17 i'm glad you mentioned this and yes, that's expected because the warning triggers when depth exceeds the threshold (100), and by the time it shows the warning (after frame 2), the depth is already 200!

src/core/main.js Outdated
this._frameRate = 1000.0 / this.deltaTime;
await this.redraw();
// Check for unmatched push/pop calls (only warn once)
const PUSH_POP_WARNING_THRESHOLD = 100;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think the threshold needs to be 100, or should it just be > 0?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought it will give some flexibility and only warns when it becomes a real problem, there is no downside of using >0. i will update it thank you @davepagurek

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

Successfully merging this pull request may close these issues.

3 participants