Skip to content

Commit 971d1fb

Browse files
committed
Fix loading documents saved before #4129 with raster images appearing missing
1 parent 077d11b commit 971d1fb

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

editor/src/messages/portfolio/document/document_message_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
573573
self.node_graph_handler.context_menu = None;
574574
responses.add(FrontendMessage::UpdateContextMenuInformation { context_menu_information: None });
575575
}
576-
// Exit one level up if inside a nested network
576+
// Go back up one level in the breadcrumb path if we're in a subgraph
577577
else if !self.breadcrumb_network_path.is_empty() {
578578
responses.add(DocumentMessage::ExitNestedNetwork { steps_back: 1 });
579579
}

editor/src/messages/portfolio/document_migration.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,30 @@ pub fn document_migration_upgrades(document: &mut DocumentMessageHandler, reset_
12261226
}
12271227
}
12281228

1229+
// The "Image" wrapper network was replaced with the `image` proto node directly. Convert old `Network("Image")` instances to the proto node, forwarding the embedded image data so the `image` pass in `migrate_node` below turns it into a resource.
1230+
// Pre-pass for the same reason as the Brush and Transform migrations above: replacing the outer Image's network impl orphans its child paths.
1231+
let image_layers: Vec<(NodeId, Vec<NodeId>)> = document
1232+
.network_interface
1233+
.document_network()
1234+
.recursive_nodes()
1235+
.filter_map(|(node_id, _, path)| (document.network_interface.reference(node_id, &path) == Some(DefinitionIdentifier::Network("Image".into()))).then_some((*node_id, path)))
1236+
.collect();
1237+
for (node_id, network_path) in &image_layers {
1238+
let _ = document.network_interface.outward_wires(network_path);
1239+
let new_reference = DefinitionIdentifier::ProtoNode(graphene_std::raster_nodes::std_nodes::image::IDENTIFIER);
1240+
let Some(definition) = resolve_document_node_type(&new_reference) else { continue };
1241+
let mut node_template = definition.default_node_template();
1242+
document.network_interface.replace_implementation(node_id, network_path, &mut node_template);
1243+
let Some(old_inputs) = document.network_interface.replace_inputs(node_id, network_path, &mut node_template) else {
1244+
continue;
1245+
};
1246+
1247+
// Forward the embedded image data into input 0, where the `migrate_node` `image` pass finds it and converts it to a resource.
1248+
if let Some(image_input) = old_inputs.into_iter().find(|input| matches!(input.as_value(), Some(TaggedValue::ImageData(_)))) {
1249+
document.network_interface.set_input(&InputConnector::node(*node_id, 0), image_input, network_path);
1250+
}
1251+
}
1252+
12291253
// Apply upgrades to each unmodified node.
12301254
let nodes = document
12311255
.network_interface

node-graph/graph-craft/src/document/value.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,11 @@ pub fn deserialize_tagged_value_with_legacy_migration<'de, D: serde::Deserialize
623623
"Graphic" | "GraphicGroup" | "Group" => return Ok(MemoHash::new(TaggedValue::TypeDefault(descriptor!(List<Graphic>)))),
624624
"Artboard" | "ArtboardGroup" => return Ok(MemoHash::new(TaggedValue::TypeDefault(descriptor!(List<Artboard>)))),
625625
"Raster" | "ImageFrame" | "RasterData" | "Image" => {
626-
let first_element = content.as_object().and_then(|c| c.get("element")).and_then(|e| e.as_array()).and_then(|arr| arr.first());
626+
let first_element = content
627+
.as_object()
628+
.and_then(|c| c.get("element").or_else(|| c.get("instance")).or_else(|| c.get("instances")))
629+
.and_then(|e| e.as_array())
630+
.and_then(|arr| arr.first());
627631
if let Some(image_value) = first_element {
628632
let image: Image<Color> = serde_json::from_value(image_value.clone()).map_err(serde::de::Error::custom)?;
629633
return Ok(MemoHash::new(TaggedValue::ImageData(image)));

0 commit comments

Comments
 (0)