浏览代码

Merge pull request #15443 from eska014/html5-fixcanvas

Fix WebGL context initialization
Rémi Verschelde 7 年之前
父节点
当前提交
57efe0bea5
共有 1 个文件被更改,包括 7 次插入3 次删除
  1. 7 3
      platform/javascript/engine.js

+ 7 - 3
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) {