Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/core/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,31 @@ class p5 {
this.deltaTime = now - this._lastRealFrameTime;
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


if (this._renderer && this._renderer._pushPopDepth > PUSH_POP_WARNING_THRESHOLD) {
if (!this._pushPopWarningShown) {
this._pushPopWarningShown = true;
p5._friendlyError(
`I detected ${this._renderer._pushPopDepth} unmatched push() calls. ` +
'Each push() should have a matching pop() call. ' +
'Unmatched push() calls can cause memory issues and performance problems.',
'push'
);
}
}

if (this._renderer && this._renderer._pushPopDepth < 0) {
if (!this._popWarningShown) {
this._popWarningShown = true;
p5._friendlyError(
'pop() was called more times than push(). ' +
'Each pop() should match a previous push() call.',
'pop'
);
}
}
this._lastTargetFrameTime = Math.max(this._lastTargetFrameTime
+ targetTimeBetweenFrames, now);
this._lastRealFrameTime = now;
Expand Down