Skip to content

Commit 743ee47

Browse files
committed
Handle failure when 3D mode fails for histogram
When 3D rendering fails - at least continue with default 2D renering to keep code working
1 parent 96c570f commit 743ee47

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

modules/hist/TH1Painter.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { TH1Painter as TH1Painter2D } from '../hist2d/TH1Painter.mjs';
1111
class TH1Painter extends TH1Painter2D {
1212

1313
/** @summary draw TH1 object in 3D mode */
14-
draw3D(reason) {
14+
async draw3D(reason) {
1515
this.mode3d = true;
1616

1717
const main = this.getFramePainter(), // who makes axis drawing

modules/hist2d/TH1Painter.mjs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,17 +1294,6 @@ class TH1Painter extends THistPainter {
12941294
return false;
12951295
}
12961296

1297-
/** @summary Call drawing function depending from 3D mode */
1298-
async callDrawFunc(reason) {
1299-
const main = this.getMainPainter(),
1300-
fp = this.getFramePainter();
1301-
1302-
if ((main !== this) && fp && (fp.mode3d !== this.options.Mode3D))
1303-
this.copyOptionsFrom(main);
1304-
1305-
return this.options.Mode3D ? this.draw3D(reason) : this.draw2D(reason);
1306-
}
1307-
13081297
/** @summary Performs 2D drawing of histogram
13091298
* @return {Promise} when ready */
13101299
async draw2D(reason) {
@@ -1332,6 +1321,24 @@ class TH1Painter extends THistPainter {
13321321
return this.draw2D(reason);
13331322
}
13341323

1324+
/** @summary Call drawing function depending from 3D mode */
1325+
async callDrawFunc(reason) {
1326+
const main = this.getMainPainter(),
1327+
fp = this.getFramePainter();
1328+
1329+
if ((main !== this) && fp && (fp.mode3d !== this.options.Mode3D))
1330+
this.copyOptionsFrom(main);
1331+
1332+
if (!this.options.Mode3D)
1333+
return this.draw2D(reason);
1334+
1335+
return this.draw3D(reason).catch(() => {
1336+
console.error('Fail to draw histogram in 3D - back to 2D')
1337+
this.options.Mode3D = false;
1338+
return this.draw2D(reason);
1339+
});
1340+
}
1341+
13351342
/** @summary Redraw histogram */
13361343
redraw(reason) {
13371344
return this.callDrawFunc(reason);

modules/hist2d/TH2Painter.mjs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3542,10 +3542,17 @@ class TH2Painter extends THistPainter {
35423542
const main = this.getMainPainter(),
35433543
fp = this.getFramePainter();
35443544

3545-
if ((main !== this) && fp && (fp.mode3d !== this.options.Mode3D))
3546-
this.copyOptionsFrom(main);
3545+
if ((main !== this) && fp && (fp.mode3d !== this.options.Mode3D))
3546+
this.copyOptionsFrom(main);
35473547

3548-
return this.options.Mode3D ? this.draw3D(reason) : this.draw2D(reason);
3548+
if (!this.options.Mode3D)
3549+
return this.draw2D(reason);
3550+
3551+
return this.draw3D(reason).catch(() => {
3552+
console.error('Fail to draw histogram in 3D - back to 2D')
3553+
this.options.Mode3D = false;
3554+
return this.draw2D(reason);
3555+
});
35493556
}
35503557

35513558
/** @summary Redraw histogram */

0 commit comments

Comments
 (0)