From b988457c13f77f50e03b4e46fbef4d5e42cfcf33 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 22 Nov 2013 17:19:14 -0800 Subject: [PATCH] listen to webglcontextcreationerror for information; fixes #1846 --- src/library_browser.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/library_browser.js b/src/library_browser.js index 8444fb732..fbc609d76 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -250,15 +250,24 @@ mergeInto(LibraryManager.library, { contextAttributes.preserveDrawingBuffer = true; #endif - ['experimental-webgl', 'webgl'].some(function(webglId) { - return ctx = canvas.getContext(webglId, contextAttributes); - }); + var errorInfo = '?'; + function onContextCreationError(event) { + errorInfo = e.statusMessage || errorInfo; + } + canvas.addEventListener('webglcontextcreationerror', onContextCreationError, false); + try { + ['experimental-webgl', 'webgl'].some(function(webglId) { + return ctx = canvas.getContext(webglId, contextAttributes); + }); + } finally { + canvas.removeEventListener('webglcontextcreationerror', onContextCreationError, false); + } } else { ctx = canvas.getContext('2d'); } if (!ctx) throw ':('; } catch (e) { - Module.print('Could not create canvas - ' + e); + Module.print('Could not create canvas: ' + [errorInfo, e]); return null; } if (useWebGL) {