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..3aa171c07a 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 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);