diff --git a/src/pattern.class.js b/src/pattern.class.js index 0100d2af..7d1cb04c 100644 --- a/src/pattern.class.js +++ b/src/pattern.class.js @@ -137,6 +137,11 @@ fabric.Pattern = fabric.util.createClass(/** @lends fabric.Pattern.prototype */ ? this.source() : this.source; + // if the image failed to load, return, and allow rest to continue loading + if (!source) { + return ''; + } + // if an image if (typeof source.src !== 'undefined') { if (!source.complete) { diff --git a/src/shapes/image.class.js b/src/shapes/image.class.js index 94f5dddf..89e09a22 100644 --- a/src/shapes/image.class.js +++ b/src/shapes/image.class.js @@ -252,7 +252,9 @@ * @return {String} Source of an image */ getSrc: function() { - return this.getElement().src || this.getElement()._src; + if (this.getElement()) { + return this.getElement().src || this.getElement()._src; + } }, /** @@ -281,6 +283,10 @@ */ applyFilters: function(callback) { + if (!this._originalElement) { + return; + } + if (this.filters.length === 0) { this._element = this._originalElement; callback && callback(); @@ -330,13 +336,13 @@ * @param {CanvasRenderingContext2D} ctx Context to render on */ _render: function(ctx) { - ctx.drawImage( - this._element, - -this.width / 2, - -this.height / 2, - this.width, - this.height - ); + this._element && ctx.drawImage( + this._element, + -this.width / 2, + -this.height / 2, + this.width, + this.height + ); }, /** @@ -368,7 +374,9 @@ options || (options = { }); this.setOptions(options); this._setWidthHeight(options); - this._element.crossOrigin = this.crossOrigin; + if (this._element) { + this._element.crossOrigin = this.crossOrigin; + } }, /** @@ -394,11 +402,15 @@ _setWidthHeight: function(options) { this.width = 'width' in options ? options.width - : (this.getElement().width || 0); + : (this.getElement() + ? this.getElement().width || 0 + : 0); this.height = 'height' in options ? options.height - : (this.getElement().height || 0); + : (this.getElement() + ? this.getElement().height || 0 + : 0); }, /** diff --git a/src/util/dom_misc.js b/src/util/dom_misc.js index fbcdf594..541cf201 100644 --- a/src/util/dom_misc.js +++ b/src/util/dom_misc.js @@ -68,7 +68,7 @@ * @param {String} className Class to add to an element */ function addClass(element, className) { - if ((' ' + element.className + ' ').indexOf(' ' + className + ' ') === -1) { + if (element && (' ' + element.className + ' ').indexOf(' ' + className + ' ') === -1) { element.className += (element.className ? ' ' : '') + className; } }