From 695ec61fc9eedf2936009d9b17cc5a79c701e624 Mon Sep 17 00:00:00 2001 From: Dobes Vandermeer Date: Fri, 2 Oct 2020 00:49:37 -0700 Subject: [PATCH] Add null check for 2d context in CanvasView --- src/view/CanvasView.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/view/CanvasView.js b/src/view/CanvasView.js index ae804aadab..deade3f0e7 100644 --- a/src/view/CanvasView.js +++ b/src/view/CanvasView.js @@ -43,6 +43,10 @@ var CanvasView = View.extend(/** @lends CanvasView# */{ canvas = CanvasProvider.getCanvas(size); } var ctx = this._context = canvas.getContext('2d'); + if (!ctx) { + throw new Error('Canvas ' + canvas + + ' is unable to provide a 2D context.'); + } // Save context right away, and restore in #remove(). Also restore() and // save() again in _setElementSize() to prevent accumulation of scaling. ctx.save();