Skip to content

Commit

Permalink
removed references to context when disposing (fabricjs#4846)
Browse files Browse the repository at this point in the history
* removed references to context
* improved test
* try fix error
  • Loading branch information
asturur authored Mar 22, 2018
1 parent bd11ddb commit 909c542
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,10 @@
this.removeListeners();
wrapper.removeChild(this.upperCanvasEl);
wrapper.removeChild(this.lowerCanvasEl);
delete this.upperCanvasEl;
this.upperCanvasEl = null;
this.cacheCanvasEl = null;
this.contextCache = null;
this.contextTop = null;
if (wrapper.parentNode) {
wrapper.parentNode.replaceChild(this.lowerCanvasEl, this.wrapperEl);
}
Expand Down
7 changes: 6 additions & 1 deletion src/static_canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,11 @@
* @chainable
*/
dispose: function () {
// cancel eventually ongoing renders
if (this.isRendering) {
fabric.util.cancelAnimFrame(this.isRendering);
this.isRendering = 0;
}
this.forEachObject(function(object) {
object.dispose && object.dispose();
});
Expand All @@ -1670,7 +1675,7 @@
this.overlayImage = null;
this._iTextInstances = null;
this.lowerCanvasEl = null;
this.cacheCanvasEl = null;
this.contextContainer = null;
return this;
},

Expand Down
3 changes: 3 additions & 0 deletions test/unit/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -1751,6 +1751,9 @@
}
assert.equal(canvas.wrapperEl, null, 'wrapperEl should be deleted');
assert.equal(canvas.upperCanvasEl, null, 'upperCanvas should be deleted');
assert.equal(canvas.cacheCanvasEl, null, 'cacheCanvasEl should be deleted');
assert.equal(canvas.contextTop, null, 'contextTop should be deleted');
assert.equal(canvas.contextCache, null, 'contextCache should be deleted');
});

// QUnit.test('dispose', function(assert) {
Expand Down
1 change: 1 addition & 0 deletions test/unit/canvas_static.js
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,7 @@
canvas2.dispose();
assert.equal(canvas2.getObjects().length, 0, 'dispose should clear canvas');
assert.equal(canvas2.lowerCanvasEl, null, 'dispose should clear lowerCanvasEl');
assert.equal(canvas2.contextContainer, null, 'dispose should clear contextContainer');
});

QUnit.test('clone', function(assert) {
Expand Down

0 comments on commit 909c542

Please sign in to comment.