Skip to content

Commit 9e864a5

Browse files
authored
Merge pull request #4549 from plotly/display-webgl
Detect correct device in the second attempt to create 3-D scene
2 parents 9aa3df9 + a26e5e2 commit 9e864a5

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

src/plots/gl3d/scene.js

+30-8
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ function Scene(options, fullLayout) {
9191

9292
var proto = Scene.prototype;
9393

94-
proto.tryCreatePlot = function() {
94+
proto.prepareOptions = function() {
9595
var scene = this;
96+
9697
var opts = {
9798
canvas: scene.canvas,
9899
gl: scene.gl,
@@ -132,20 +133,41 @@ proto.tryCreatePlot = function() {
132133
opts.canvas = STATIC_CANVAS;
133134
}
134135

135-
var failed = 0;
136+
return opts;
137+
};
138+
139+
proto.tryCreatePlot = function() {
140+
var scene = this;
141+
142+
var opts = scene.prepareOptions();
143+
144+
var success = true;
136145

137146
try {
138147
scene.glplot = createPlot(opts);
139148
} catch(e) {
140-
failed++;
141-
try { // try second time to fix issue with Chrome 77 https://github.com/plotly/plotly.js/issues/4233
142-
scene.glplot = createPlot(opts);
143-
} catch(e) {
144-
failed++;
149+
if(scene.staticMode) {
150+
success = false;
151+
} else { // try second time
152+
try {
153+
// invert preserveDrawingBuffer setup which could be resulted from is-mobile not detecting the right device
154+
Lib.warn([
155+
'webgl setup failed possibly due to',
156+
isMobile ? 'disabling' : 'enabling',
157+
'preserveDrawingBuffer config.',
158+
'The device may not be supported by isMobile module!',
159+
'Inverting preserveDrawingBuffer option in second attempt to create webgl scene.'
160+
].join(' '));
161+
isMobile = opts.glOptions.preserveDrawingBuffer = !opts.glOptions.preserveDrawingBuffer;
162+
163+
scene.glplot = createPlot(opts);
164+
} catch(e) {
165+
success = false;
166+
}
145167
}
146168
}
147169

148-
return failed < 2;
170+
return success;
149171
};
150172

151173
proto.initializeGLCamera = function() {

0 commit comments

Comments
 (0)