mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 23:08:05 +08:00
Fix most known issues with migrations failing to open documents from the past year (#3148)
This commit is contained in:
@@ -1786,7 +1786,7 @@ impl DocumentMessageHandler {
|
||||
pub fn deserialize_document(serialized_content: &str) -> Result<Self, EditorError> {
|
||||
let document_message_handler = serde_json::from_str::<DocumentMessageHandler>(serialized_content)
|
||||
.or_else(|e| {
|
||||
log::warn!("failed to directly load document with the following error: {e}. Trying old DocumentMessageHandler");
|
||||
log::warn!("Failed to directly load document with the following error: {e}. Trying old DocumentMessageHandler.");
|
||||
// TODO: Eventually remove this document upgrade code
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub struct OldDocumentMessageHandler {
|
||||
|
||||
@@ -16,7 +16,13 @@ pub enum EditorError {
|
||||
#[error("The operation caused a document error:\n{0:?}")]
|
||||
Document(String),
|
||||
|
||||
#[error("This document was created in an older version of the editor.\n\nBackwards compatibility is, regrettably, not present in the current alpha release.\n\nTechnical details:\n{0:?}")]
|
||||
#[error(
|
||||
"This document was created in an older version of the editor.\n\
|
||||
\n\
|
||||
Full backwards compatibility is not guaranteed in the current alpha release.\n\
|
||||
\n\
|
||||
If this document is critical, ask for support in Graphite's Discord community."
|
||||
)]
|
||||
DocumentDeserialization(String),
|
||||
|
||||
#[error("{0}")]
|
||||
|
||||
@@ -568,7 +568,7 @@ impl NodeNetworkInterface {
|
||||
let skip_footprint = 1;
|
||||
|
||||
let Some(input_type) = std::iter::once(node_types.call_argument.clone()).chain(node_types.inputs.clone()).nth(input_index + skip_footprint) else {
|
||||
log::error!("Could not get type for {node_id_path:?}, input: {input_index}");
|
||||
// log::warn!("Could not get type for {node_id_path:?}, input: {input_index}");
|
||||
return (concrete!(()), TypeSource::Error("could not get the protonode's input"));
|
||||
};
|
||||
|
||||
@@ -2629,7 +2629,7 @@ impl NodeNetworkInterface {
|
||||
InputConnector::Node { node_id, input_index } => {
|
||||
let Some(node_metadata) = self.node_metadata_mut(node_id, network_path) else { return };
|
||||
let Some(input_metadata) = node_metadata.persistent_metadata.input_metadata.get_mut(*input_index) else {
|
||||
log::error!("Node metadata must exist on node: {input:?}");
|
||||
// log::warn!("Node metadata must exist on node: {input:?}");
|
||||
return;
|
||||
};
|
||||
let wire_update = WirePathUpdate {
|
||||
@@ -2721,7 +2721,7 @@ impl NodeNetworkInterface {
|
||||
return;
|
||||
};
|
||||
let Some(input_metadata) = node_metadata.persistent_metadata.input_metadata.get_mut(*input_index) else {
|
||||
log::error!("Node metadata must exist on node: {input:?}");
|
||||
// log::warn!("Node metadata must exist on node: {input:?}");
|
||||
return;
|
||||
};
|
||||
input_metadata.transient_metadata.wire = TransientMetadata::Unloaded;
|
||||
|
||||
@@ -113,6 +113,10 @@ const NODE_REPLACEMENTS: &[NodeReplacement<'static>] = &[
|
||||
node: graphene_std::math_nodes::root::IDENTIFIER,
|
||||
aliases: &["graphene_core::ops::RootNode"],
|
||||
},
|
||||
NodeReplacement {
|
||||
node: graphene_std::math_nodes::absolute_value::IDENTIFIER,
|
||||
aliases: &["graphene_core::ops::AbsoluteValueNode"],
|
||||
},
|
||||
NodeReplacement {
|
||||
node: graphene_std::math_nodes::logarithm::IDENTIFIER,
|
||||
aliases: &["graphene_core::ops::LogarithmNode"],
|
||||
|
||||
@@ -79,6 +79,7 @@ pub enum PortfolioMessage {
|
||||
document_is_saved: bool,
|
||||
document_serialized_content: String,
|
||||
to_front: bool,
|
||||
select_after_open: bool,
|
||||
},
|
||||
ToggleResetNodesToDefinitionsOnOpen,
|
||||
PasteIntoFolder {
|
||||
|
||||
@@ -422,17 +422,16 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio
|
||||
document_path,
|
||||
document_serialized_content,
|
||||
} => {
|
||||
let document_id = DocumentId(generate_uuid());
|
||||
responses.add(PortfolioMessage::OpenDocumentFileWithId {
|
||||
document_id,
|
||||
document_id: DocumentId(generate_uuid()),
|
||||
document_name,
|
||||
document_path,
|
||||
document_is_auto_saved: false,
|
||||
document_is_saved: true,
|
||||
document_serialized_content,
|
||||
to_front: false,
|
||||
select_after_open: true,
|
||||
});
|
||||
responses.add(PortfolioMessage::SelectDocument { document_id });
|
||||
}
|
||||
PortfolioMessage::ToggleResetNodesToDefinitionsOnOpen => {
|
||||
self.reset_node_definitions_on_open = !self.reset_node_definitions_on_open;
|
||||
@@ -446,6 +445,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio
|
||||
document_is_saved,
|
||||
document_serialized_content,
|
||||
to_front,
|
||||
select_after_open,
|
||||
} => {
|
||||
// Upgrade the document being opened to use fresh copies of all nodes
|
||||
let reset_node_definitions_on_open = reset_node_definitions_on_open || document_migration_reset_node_definition(&document_serialized_content);
|
||||
@@ -540,6 +540,10 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio
|
||||
|
||||
// Load the document into the portfolio so it opens in the editor
|
||||
self.load_document(document, document_id, self.layers_panel_open, responses, to_front);
|
||||
|
||||
if select_after_open {
|
||||
responses.add(PortfolioMessage::SelectDocument { document_id });
|
||||
}
|
||||
}
|
||||
PortfolioMessage::PasteIntoFolder { clipboard, parent, insert_index } => {
|
||||
let mut all_new_ids = Vec::new();
|
||||
@@ -954,14 +958,15 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio
|
||||
}
|
||||
PortfolioMessage::SubmitGraphRender { document_id, ignore_hash } => {
|
||||
let node_to_inspect = self.node_to_inspect();
|
||||
let result = self.executor.submit_node_graph_evaluation(
|
||||
self.documents.get_mut(&document_id).expect("Tried to render non-existent document"),
|
||||
document_id,
|
||||
ipp.viewport_bounds.size().as_uvec2(),
|
||||
timing_information,
|
||||
node_to_inspect,
|
||||
ignore_hash,
|
||||
);
|
||||
let Some(document) = self.documents.get_mut(&document_id) else {
|
||||
log::error!("Tried to render non-existent document");
|
||||
return;
|
||||
};
|
||||
let viewport_resolution = ipp.viewport_bounds.size().as_uvec2();
|
||||
|
||||
let result = self
|
||||
.executor
|
||||
.submit_node_graph_evaluation(document, document_id, viewport_resolution, timing_information, node_to_inspect, ignore_hash);
|
||||
|
||||
match result {
|
||||
Err(description) => {
|
||||
@@ -1173,7 +1178,7 @@ impl PortfolioMessageHandler {
|
||||
|
||||
/// Returns an iterator over the open documents in order.
|
||||
pub fn ordered_document_iterator(&self) -> impl Iterator<Item = &DocumentMessageHandler> {
|
||||
self.document_ids.iter().map(|id| self.documents.get(id).expect("document id was not found in the document hashmap"))
|
||||
self.document_ids.iter().map(|id| self.documents.get(id).expect("Document id was not found in the document hashmap"))
|
||||
}
|
||||
|
||||
fn document_index(&self, document_id: DocumentId) -> usize {
|
||||
|
||||
Reference in New Issue
Block a user