diff --git a/lib/canvas-layer.js b/lib/canvas-layer.js index 95189b94..3b7d4b09 100644 --- a/lib/canvas-layer.js +++ b/lib/canvas-layer.js @@ -61,19 +61,25 @@ module.exports = class CanvasLayer { } copyToOffscreen () { - this.offscreenContext.drawImage(this.canvas, 0, 0) + if (this.canvas.width > 0 && this.canvas.height > 0) { + this.offscreenContext.drawImage(this.canvas, 0, 0) + } } copyFromOffscreen () { - this.context.drawImage(this.offscreenCanvas, 0, 0) + if (this.offscreenCanvas.width > 0 && this.offscreenCanvas.height > 0) { + this.context.drawImage(this.offscreenCanvas, 0, 0) + } } copyPartFromOffscreen (srcY, destY, height) { - this.context.drawImage( - this.offscreenCanvas, - 0, srcY, this.offscreenCanvas.width, height, - 0, destY, this.offscreenCanvas.width, height - ) + if (this.offscreenCanvas.width > 0 && this.offscreenCanvas.height > 0) { + this.context.drawImage( + this.offscreenCanvas, + 0, srcY, this.offscreenCanvas.width, height, + 0, destY, this.offscreenCanvas.width, height + ) + } } clearCanvas () {