From 96b182f1fd41dc9389f1b34b37c7422dda4a5b95 Mon Sep 17 00:00:00 2001 From: Philipp Schaad Date: Wed, 30 Oct 2024 12:24:28 +0100 Subject: [PATCH] Avoid crashing the renderer on bad layouts --- src/layouter/layout.ts | 2 +- src/layouter/state_machine/sm_layouter.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/layouter/layout.ts b/src/layouter/layout.ts index 88c2288..4e100c3 100644 --- a/src/layouter/layout.ts +++ b/src/layouter/layout.ts @@ -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); } diff --git a/src/layouter/state_machine/sm_layouter.ts b/src/layouter/state_machine/sm_layouter.ts index 97a4a67..67c45df 100644 --- a/src/layouter/state_machine/sm_layouter.ts +++ b/src/layouter/state_machine/sm_layouter.ts @@ -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), + }, + ]; + } } }