Skip to content

Commit b9064db

Browse files
authored
Merge pull request #3403 from cytoscape/fix/webgl-invalid-pts
Add webgl edge guard in texture getter
2 parents 42aced8 + 82ae6e3 commit b9064db

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/extensions/renderer/canvas/webgl/drawing-elements-webgl.mjs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,13 @@ export class ElementDrawingWebGL {
556556
return;
557557
}
558558

559+
// Edges with invalid points could be passed here (labels), causing errors
560+
// Ref: Random "Script Error" thrown when generating nodes and edges in newest webgl version #3365
561+
// https://github.com/cytoscape/cytoscape.js/issues/3365
562+
if(ele.isEdge() && !this._isValidEdge(ele)) {
563+
return;
564+
}
565+
559566
if(this.renderTarget.picking && opts.getTexPickingMode) {
560567
const mode = opts.getTexPickingMode(ele);
561568
if(mode === TEX_PICKING_MODE.IGNORE) {
@@ -989,11 +996,21 @@ export class ElementDrawingWebGL {
989996
}
990997
}
991998

999+
_isValidEdge(edge) {
1000+
const rs = edge._private.rscratch;
1001+
1002+
if( rs.badLine || rs.allpts == null || isNaN(rs.allpts[0]) ){ // isNaN in case edge is impossible and browser bugs (e.g. safari)
1003+
return false;
1004+
}
1005+
1006+
return true;
1007+
}
1008+
9921009
_getEdgePoints(edge) {
9931010
const rs = edge._private.rscratch;
9941011

9951012
// if bezier ctrl pts can not be calculated, then die
996-
if( rs.badLine || rs.allpts == null || isNaN(rs.allpts[0]) ){ // isNaN in case edge is impossible and browser bugs (e.g. safari)
1013+
if(!this._isValidEdge(edge)){ // isNaN in case edge is impossible and browser bugs (e.g. safari)
9971014
return;
9981015
}
9991016
const controlPoints = rs.allpts;

0 commit comments

Comments
 (0)