Browse Source

Merge pull request #18037 from mgreter/graceful-partial-offscreen-canvas-2d

Handle UA with partial OffscreenCanvas more gracefully
Mr.doob 5 years ago
parent
commit
260e58e46e
1 changed files with 13 additions and 2 deletions
  1. 13 2
      src/renderers/webgl/WebGLTextures.js

+ 13 - 2
src/renderers/webgl/WebGLTextures.js

@@ -18,9 +18,20 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
 
 
 	// cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
 	// cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
 	// also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
 	// also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
+	// Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
 
 
-	var useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined'
-		&& ( new OffscreenCanvas( 1, 1 ).getContext( "2d" ) ) !== null;
+	var useOffscreenCanvas = false;
+
+	try {
+
+		useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined'
+			&& ( new OffscreenCanvas( 1, 1 ).getContext( "2d" ) ) !== null;
+
+	} catch ( err ) {
+
+		// Ignore any errors
+
+	}
 
 
 	function createCanvas( width, height ) {
 	function createCanvas( width, height ) {