Browse Source

Fix error when changing a subgraph input count

Leonardo Jeanteur 4 years ago
parent
commit
b45ab2f6a2
2 changed files with 9 additions and 4 deletions
  1. 0 1
      hide/view/shadereditor/ShaderEditor.hx
  2. 9 3
      hrt/shgraph/ShaderGraph.hx

+ 0 - 1
hide/view/shadereditor/ShaderEditor.hx

@@ -452,7 +452,6 @@ class ShaderEditor extends hide.view.Graph {
 				}
 				}
 				if( !found )
 				if( !found )
 					watch(subGraphNode.pathShaderGraph, rebuild, { keepOnRebuild: false });
 					watch(subGraphNode.pathShaderGraph, rebuild, { keepOnRebuild: false });
-				trace("watching", subGraphNode.pathShaderGraph);
 			}
 			}
 		}
 		}
 
 

+ 9 - 3
hrt/shgraph/ShaderGraph.hx

@@ -118,6 +118,15 @@ class ShaderGraph {
 		var output = this.nodes.get(edge.idOutput);
 		var output = this.nodes.get(edge.idOutput);
 		node.instance.setInput(edge.nameInput, new NodeVar(output.instance, edge.nameOutput));
 		node.instance.setInput(edge.nameInput, new NodeVar(output.instance, edge.nameOutput));
 		output.outputs.push(node);
 		output.outputs.push(node);
+
+		var subShaderIn = Std.downcast(node.instance, hrt.shgraph.nodes.SubGraph);
+		var subShaderOut = Std.downcast(output.instance, hrt.shgraph.nodes.SubGraph);
+		if( @:privateAccess ((subShaderIn != null) && !subShaderIn.inputInfoKeys.contains(edge.nameInput))
+			|| @:privateAccess ((subShaderOut != null) && !subShaderOut.outputInfoKeys.contains(edge.nameOutput))
+		) {
+			removeEdge(edge.idInput, edge.nameInput, false);
+		}
+
 		#if editor
 		#if editor
 		if (hasCycle()){
 		if (hasCycle()){
 			removeEdge(edge.idInput, edge.nameInput, false);
 			removeEdge(edge.idInput, edge.nameInput, false);
@@ -282,9 +291,6 @@ class ShaderGraph {
 		var contentFragment = [];
 		var contentFragment = [];
 
 
 		for (n in nodes) {
 		for (n in nodes) {
-			if (subShaderId != null && Std.is(n.instance, hrt.shgraph.nodes.SubGraph)) {
-				throw ShaderException.t("A subgraph can't have a subgraph", -1);
-			}
 			if (!variableNamesAlreadyUpdated && subShaderId != null && !Std.is(n.instance, ShaderInput)) {
 			if (!variableNamesAlreadyUpdated && subShaderId != null && !Std.is(n.instance, ShaderInput)) {
 				for (outputKey in n.instance.getOutputInfoKeys()) {
 				for (outputKey in n.instance.getOutputInfoKeys()) {
 					var output = n.instance.getOutput(outputKey);
 					var output = n.instance.getOutput(outputKey);