From 9c80c453aa94eef3895bdfeb921dc5425351fab3 Mon Sep 17 00:00:00 2001 From: Dan Royer Date: Wed, 27 Sep 2023 13:54:24 -0700 Subject: [PATCH] more safety checks --- .../com/marginallyclever/nodegraphcore/Subgraph.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/marginallyclever/nodegraphcore/Subgraph.java b/src/main/java/com/marginallyclever/nodegraphcore/Subgraph.java index 2bc17ee..323c797 100644 --- a/src/main/java/com/marginallyclever/nodegraphcore/Subgraph.java +++ b/src/main/java/com/marginallyclever/nodegraphcore/Subgraph.java @@ -9,7 +9,7 @@ public class Subgraph extends Node implements SupergraphInput, SupergraphOutput, PrintWithGraphics { private final Graph graph = new Graph(); - private class VariablePair { + static class VariablePair { public Dock superVariable; public Dock subVariable; @@ -43,11 +43,14 @@ public Subgraph(Graph graph) { /** * Stores a deep copy of the given graph and exposes the {@link SupergraphInput}s and {@link SupergraphOutput}s to * the supergraph. - * @param graph the {@link Graph} to store. + * @param graph the {@link Graph} to store. A deep copy is made. */ public void setGraph(Graph graph) { this.graph.clear(); - this.graph.add(graph.deepCopy()); + + if(graph!=null) { + this.graph.add(graph.deepCopy()); + } for(Node n : this.graph.getNodes()) { extractSupergraphInputs(n); @@ -106,7 +109,7 @@ private void extractSupergraphInputs(Node n) { private int sortVariables(VariablePair a, VariablePair b) { // all input first int aIn = (a.subVariable instanceof DockReceiving)?1:0; - int bIn = (a.subVariable instanceof DockReceiving)?1:0; + int bIn = (b.subVariable instanceof DockReceiving)?1:0; if(aIn != bIn) return aIn-bIn; // then sort by name alphabetically return a.subVariable.getName().compareTo(b.subVariable.getName());