diff --git a/src/plots/gl3d/scene.js b/src/plots/gl3d/scene.js index e45fb6e932a..3aef87d74a3 100644 --- a/src/plots/gl3d/scene.js +++ b/src/plots/gl3d/scene.js @@ -136,6 +136,8 @@ proto.prepareOptions = function() { return opts; }; +var firstInit = true; + proto.tryCreatePlot = function() { var scene = this; @@ -146,7 +148,7 @@ proto.tryCreatePlot = function() { try { scene.glplot = createPlot(opts); } catch(e) { - if(scene.staticMode) { + if(scene.staticMode || !firstInit) { success = false; } else { // try second time try { @@ -158,15 +160,22 @@ proto.tryCreatePlot = function() { 'The device may not be supported by is-mobile module!', 'Inverting preserveDrawingBuffer option in second attempt to create webgl scene.' ].join(' ')); + + // invert is-mobile isMobile = opts.glOptions.preserveDrawingBuffer = !opts.glOptions.preserveDrawingBuffer; scene.glplot = createPlot(opts); } catch(e) { + // revert changes to is-mobile + isMobile = opts.glOptions.preserveDrawingBuffer = !opts.glOptions.preserveDrawingBuffer; + success = false; } } } + firstInit = false; + return success; }; @@ -238,43 +247,45 @@ proto.initializeGLPlot = function() { scene.graphDiv.emit('plotly_relayout', update); }; - scene.glplot.canvas.addEventListener('mouseup', function() { - relayoutCallback(scene); - }); + if(scene.glplot.canvas) { + scene.glplot.canvas.addEventListener('mouseup', function() { + relayoutCallback(scene); + }); - scene.glplot.canvas.addEventListener('wheel', function(e) { - if(gd._context._scrollZoom.gl3d) { - if(scene.camera._ortho) { - var s = (e.deltaX > e.deltaY) ? 1.1 : 1.0 / 1.1; - var o = scene.glplot.getAspectratio(); - scene.glplot.setAspectratio({ - x: s * o.x, - y: s * o.y, - z: s * o.z - }); - } + scene.glplot.canvas.addEventListener('wheel', function(e) { + if(gd._context._scrollZoom.gl3d) { + if(scene.camera._ortho) { + var s = (e.deltaX > e.deltaY) ? 1.1 : 1.0 / 1.1; + var o = scene.glplot.getAspectratio(); + scene.glplot.setAspectratio({ + x: s * o.x, + y: s * o.y, + z: s * o.z + }); + } - relayoutCallback(scene); - } - }, passiveSupported ? {passive: false} : false); + relayoutCallback(scene); + } + }, passiveSupported ? {passive: false} : false); - scene.glplot.canvas.addEventListener('mousemove', function() { - if(scene.fullSceneLayout.dragmode === false) return; - if(scene.camera.mouseListener.buttons === 0) return; + scene.glplot.canvas.addEventListener('mousemove', function() { + if(scene.fullSceneLayout.dragmode === false) return; + if(scene.camera.mouseListener.buttons === 0) return; - var update = makeUpdate(); - scene.graphDiv.emit('plotly_relayouting', update); - }); + var update = makeUpdate(); + scene.graphDiv.emit('plotly_relayouting', update); + }); - if(!scene.staticMode) { - scene.glplot.canvas.addEventListener('webglcontextlost', function(event) { - if(gd && gd.emit) { - gd.emit('plotly_webglcontextlost', { - event: event, - layer: scene.id - }); - } - }, false); + if(!scene.staticMode) { + scene.glplot.canvas.addEventListener('webglcontextlost', function(event) { + if(gd && gd.emit) { + gd.emit('plotly_webglcontextlost', { + event: event, + layer: scene.id + }); + } + }, false); + } } scene.glplot.oncontextloss = function() {