Fix preprocessor crash when document nodes have outdated input counts

This commit is contained in:
Keavon Chambers 2026-04-01 19:39:12 -07:00
parent 211b9113a1
commit 79bf1ab688
1 changed files with 8 additions and 0 deletions

View File

@ -19,6 +19,13 @@ pub fn expand_network(network: &mut NodeNetwork, substitutions: &HashMap<ProtoNo
DocumentNodeImplementation::Network(node_network) => expand_network(node_network, substitutions), DocumentNodeImplementation::Network(node_network) => expand_network(node_network, substitutions),
DocumentNodeImplementation::ProtoNode(proto_node_identifier) => { DocumentNodeImplementation::ProtoNode(proto_node_identifier) => {
if let Some(new_node) = substitutions.get(proto_node_identifier) { if let Some(new_node) = substitutions.get(proto_node_identifier) {
// Reconcile the document node's inputs with what the current node definition expects,
// since the saved document may have fewer or more inputs than the current version
while node.inputs.len() < new_node.inputs.len() {
node.inputs.push(new_node.inputs[node.inputs.len()].clone());
}
node.inputs.truncate(new_node.inputs.len());
node.implementation = new_node.implementation.clone(); node.implementation = new_node.implementation.clone();
} }
} }
@ -59,6 +66,7 @@ pub fn generate_node_substitutions() -> HashMap<ProtoNodeIdentifier, DocumentNod
let mut generated_nodes = 0; let mut generated_nodes = 0;
let mut nodes: HashMap<_, _, _> = node_io_types let mut nodes: HashMap<_, _, _> = node_io_types
.iter() .iter()
.take(input_count)
.enumerate() .enumerate()
.map(|(i, inputs)| { .map(|(i, inputs)| {
( (