From cca799dd5681f58f43118067e9d2446d7ed8ed36 Mon Sep 17 00:00:00 2001 From: yugalkaushik Date: Fri, 20 Feb 2026 16:29:21 +0000 Subject: [PATCH 1/2] Fix p5.Graphics.size() with error message --- src/dom/dom.js | 7 +++++++ test/unit/core/p5.Graphics.js | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/dom/dom.js b/src/dom/dom.js index a5e1c54a5c..8793874107 100644 --- a/src/dom/dom.js +++ b/src/dom/dom.js @@ -3683,6 +3683,13 @@ p5.Element.prototype.size = function (w, h) { if (arguments.length === 0) { return { width: this.elt.offsetWidth, height: this.elt.offsetHeight }; } else { + if (this instanceof p5.Graphics) { + p5._friendlyError( + 'size() is not supported for p5.Graphics. Use resizeCanvas() instead.', + 'p5.Graphics.size' + ); + return this; + } let aW = w; let aH = h; const AUTO = p5.prototype.AUTO; diff --git a/test/unit/core/p5.Graphics.js b/test/unit/core/p5.Graphics.js index 216f4e9d26..38bafb014f 100644 --- a/test/unit/core/p5.Graphics.js +++ b/test/unit/core/p5.Graphics.js @@ -185,6 +185,17 @@ suite('Graphics', function() { }); }); + suite('p5.Graphics.size()', function () { + test('it shows friendly error when size() is called', function () { + var graph = myp5.createGraphics(100, 100); + var consoleStub = sinon.stub(console, 'error'); + graph.size(50, 50); + assert(consoleStub.called); + assert.include(consoleStub.getCall(0).args[0], 'resizeCanvas()'); + consoleStub.restore(); + }); + }); + suite('p5.Graphics.remove()', function() { test('it sets properties to undefined after removal', function() { var graph = myp5.createGraphics(10, 17); From ea66279d8aeae55a76a0670e7fd5a5a270c6f27b Mon Sep 17 00:00:00 2001 From: yugalkaushik Date: Fri, 20 Feb 2026 16:32:13 +0000 Subject: [PATCH 2/2] Fix p5.Graphics.size() with error message --- test/unit/core/p5.Graphics.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/core/p5.Graphics.js b/test/unit/core/p5.Graphics.js index 38bafb014f..3aa171c07a 100644 --- a/test/unit/core/p5.Graphics.js +++ b/test/unit/core/p5.Graphics.js @@ -186,7 +186,7 @@ suite('Graphics', function() { }); suite('p5.Graphics.size()', function () { - test('it shows friendly error when size() is called', function () { + test('it shows error when size() is called', function () { var graph = myp5.createGraphics(100, 100); var consoleStub = sinon.stub(console, 'error'); graph.size(50, 50);