Skip to content

Commit

Permalink
Fix set element not clearing webgl texture cache (#4410)
Browse files Browse the repository at this point in the history
* fix and test

* fix test
  • Loading branch information
asturur committed Oct 25, 2017
1 parent 3efd895 commit 2e33761
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/shapes/image.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@
* @chainable
*/
setElement: function(element, options) {
var backend = fabric.filterBackend;
if (backend && backend.evictCachesForKey) {
backend.evictCachesForKey(this.cacheKey);
}
this._element = element;
this._originalElement = element;
this._initConfig(options);
Expand Down
19 changes: 19 additions & 0 deletions test/unit/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,29 @@
assert.ok(typeof image.setElement === 'function');

var elImage = _createImageElement();
assert.notEqual(image.getElement(), elImage);
assert.equal(image.setElement(elImage), image, 'chainable');
assert.equal(image.getElement(), elImage);
assert.equal(image._originalElement, elImage);
done();
});
});

QUnit.test('setElement resets the webgl cache', function(assert) {
var done = assert.async();
var fabricBackend = fabric.filterBackend;
createImageObject(function(image) {
fabric.filterBackend = {
textureCache: {},
evictCachesForKey: function(key) {
delete this.textureCache[key];
}
};
var elImage = _createImageElement();
fabric.filterBackend.textureCache[image.cacheKey] = 'something';
assert.equal(image.setElement(elImage), image, 'chainable');
assert.equal(fabric.filterBackend.textureCache[image.cacheKey], undefined);
fabric.filterBackend = fabricBackend;
done();
});
});
Expand Down

0 comments on commit 2e33761

Please sign in to comment.