From 2dbf8251bc2a3018890ad8c874cda44dcc6dbdc4 Mon Sep 17 00:00:00 2001 From: Leon Krause Date: Sun, 7 Jan 2018 15:48:30 +0100 Subject: [PATCH] Initialize WebGL context in OS --- platform/javascript/engine.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/platform/javascript/engine.js b/platform/javascript/engine.js index dc4bdc7efb6..bca1851f402 100644 --- a/platform/javascript/engine.js +++ b/platform/javascript/engine.js @@ -138,13 +138,17 @@ } var actualCanvas = this.rtenv.canvas; - var context = false; + var testContext = false; + var testCanvas; try { - context = actualCanvas.getContext('webgl2') || actualCanvas.getContext('experimental-webgl2'); + testCanvas = document.createElement('canvas'); + testContext = testCanvas.getContext('webgl2') || testCanvas.getContext('experimental-webgl2'); } catch (e) {} - if (!context) { + if (!testContext) { throw new Error("WebGL 2 not available"); } + testCanvas = null; + testContext = null; // canvas can grab focus on click if (actualCanvas.tabIndex < 0) {