Skip to content

Commit

Permalink
Avoid crashing the renderer on bad layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
phschaad committed Oct 30, 2024
1 parent 9944b47 commit 96b182f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/layouter/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ function layoutControlFlowRegion(
// Fall back to dagre for anything that cannot be laid out with
// the vertical layout (e.g., irreducible control flow).
try {
SMLayouter.layoutDagreCompat(g, sdfg.start_block?.toString());
SMLayouter.layoutDagreCompat(g, cfg.start_block?.toString());
} catch (_ignored) {
dagre.layout(g);
}
Expand Down
17 changes: 17 additions & 0 deletions src/layouter/state_machine/sm_layouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,23 @@ export class SMLayouter {
'The following edges were not routed:',
unrouted
);
// To avoid crashing, simply straight-route these edges.
for (const edge of unrouted) {
const srcNode = this.graph.get((edge as any).src);
const dstNode = this.graph.get((edge as any).dst);
if (!srcNode || !dstNode)
throw Error('Unrouted edge may not be straight-routed.');
edge.points = [
{
x: srcNode.x,
y: srcNode.y + (srcNode.height / 2),
},
{
x: dstNode.x,
y: dstNode.y - (dstNode.height / 2),
},
];
}
}
}

Expand Down

0 comments on commit 96b182f

Please sign in to comment.