From 3e70cb86195b0d23c8763fa439c439029ee41945 Mon Sep 17 00:00:00 2001 From: Homaid Date: Tue, 28 Oct 2025 13:34:49 +0530 Subject: [PATCH 1/2] Add unmatched push/pop warning --- src/core/main.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/core/main.js b/src/core/main.js index 2feea320ca..42a477d920 100644 --- a/src/core/main.js +++ b/src/core/main.js @@ -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; + + 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; From 1c6cdc435d1df31a4e0f955ae02878e228527891 Mon Sep 17 00:00:00 2001 From: Homaid Date: Fri, 31 Oct 2025 11:25:34 +0530 Subject: [PATCH 2/2] update the thresshold --- src/core/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/main.js b/src/core/main.js index 42a477d920..45aff70dfe 100644 --- a/src/core/main.js +++ b/src/core/main.js @@ -302,7 +302,7 @@ class p5 { this._frameRate = 1000.0 / this.deltaTime; await this.redraw(); // Check for unmatched push/pop calls (only warn once) - const PUSH_POP_WARNING_THRESHOLD = 100; + const PUSH_POP_WARNING_THRESHOLD = 0; if (this._renderer && this._renderer._pushPopDepth > PUSH_POP_WARNING_THRESHOLD) { if (!this._pushPopWarningShown) {