From c24e8ceedfd59d79cf4a61926068b16edf2c964c Mon Sep 17 00:00:00 2001 From: A Date: Fri, 23 Sep 2016 15:57:35 -0400 Subject: [PATCH 1/2] Fix IndexSizeError on IE and Edge #1033 Internet Explorer and Microsoft Edge throw IndexSizeError when you call context.drawImage with negative x or y or width or height greater than the canvas width or height respectively. --- src/drawer.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/drawer.js b/src/drawer.js index 661663d1..77a4c8a1 100644 --- a/src/drawer.js +++ b/src/drawer.js @@ -423,6 +423,24 @@ $.Drawer.prototype = { this.context.globalCompositeOperation = compositeOperation; } if (bounds) { + // Internet Explorer and Microsoft Edge throw IndexSizeError + // when you call context.drawImage with negative x or y + // or width or height greater than the canvas width or height respectively + if (bounds.x < 0) { + bounds.width += bounds.x; + bounds.x = 0; + } + if (bounds.width > this.sketchCanvas.width) { + bounds.width = this.sketchCanvas.width; + } + if (bounds.y < 0) { + bounds.height += bounds.y; + bounds.y = 0; + } + if (bounds.height > this.sketchCanvas.height) { + bounds.height = this.sketchCanvas.height; + } + this.context.drawImage( this.sketchCanvas, bounds.x, From e38c53ff3146d8c0b26b06f56c65a03eea809fc4 Mon Sep 17 00:00:00 2001 From: A Date: Fri, 23 Sep 2016 16:19:08 -0400 Subject: [PATCH 2/2] Use canvas instead of sketchCanvas --- src/drawer.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/drawer.js b/src/drawer.js index 77a4c8a1..cc13cacb 100644 --- a/src/drawer.js +++ b/src/drawer.js @@ -430,15 +430,15 @@ $.Drawer.prototype = { bounds.width += bounds.x; bounds.x = 0; } - if (bounds.width > this.sketchCanvas.width) { - bounds.width = this.sketchCanvas.width; + if (bounds.width > this.canvas.width) { + bounds.width = this.canvas.width; } if (bounds.y < 0) { bounds.height += bounds.y; bounds.y = 0; } - if (bounds.height > this.sketchCanvas.height) { - bounds.height = this.sketchCanvas.height; + if (bounds.height > this.canvas.height) { + bounds.height = this.canvas.height; } this.context.drawImage(