From 4f446020baff4b8d1b3ec98d65f743210e81baa0 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Fri, 26 Jan 2018 11:12:27 +0100 Subject: [PATCH] added a simple test (#4647) --- src/shapes/object.class.js | 12 +++++++++--- test/unit/image.js | 12 ++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index 9bbe5cdc..b633010f 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -1429,7 +1429,11 @@ el.width = boundingRect.width; el.height = boundingRect.height; fabric.util.wrapElement(el, 'div'); - var canvas = new fabric.StaticCanvas(el, { enableRetinaScaling: options.enableRetinaScaling }); + var canvas = new fabric.StaticCanvas(el, { + enableRetinaScaling: options.enableRetinaScaling, + renderOnAddRemove: false, + skipOffscreen: false, + }); // to avoid common confusion https://github.com/kangax/fabric.js/issues/806 if (options.format === 'jpg') { options.format = 'jpeg'; @@ -1449,10 +1453,12 @@ var originalCanvas = this.canvas; canvas.add(this); var data = canvas.toDataURL(options); - this.set(origParams).setCoords(); this.canvas = originalCanvas; - + // canvas.dispose will call image.dispose that will nullify the elements + // since this canvas is a simple element for the process, we remove references + // to objects in this way in order to avoid object trashing. + canvas._objects = []; canvas.dispose(); canvas = null; diff --git a/test/unit/image.js b/test/unit/image.js index b7768e4b..679a4ca8 100644 --- a/test/unit/image.js +++ b/test/unit/image.js @@ -567,4 +567,16 @@ done(); }); }); + + QUnit.test('consecutive dataURLs give same result.', function(assert) { + var done = assert.async(); + createImageObject(function(image) { + var data1 = image.toDataURL(); + var data2 = image.toDataURL(); + var data3 = image.toDataURL(); + assert.equal(data1, data2, 'dataurl does not change 1'); + assert.equal(data1, data3, 'dataurl does not change 2'); + done(); + }); + }); })();