Skip to content

Commit 35ce634

Browse files
committed
Track graph execution id to associate messages with their corresponding execution id
1 parent 0c91327 commit 35ce634

File tree

12 files changed

+47
-41
lines changed

12 files changed

+47
-41
lines changed

editor/src/dispatcher.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ const SIDE_EFFECT_FREE_MESSAGES: &[MessageDiscriminant] = &[
5151
MessageDiscriminant::Frontend(FrontendMessageDiscriminant::UpdateDocumentLayerStructure),
5252
MessageDiscriminant::Frontend(FrontendMessageDiscriminant::TriggerFontLoad),
5353
];
54-
const DEBUG_MESSAGE_BLOCK_LIST: &[MessageDiscriminant] = &[MessageDiscriminant::Broadcast(BroadcastMessageDiscriminant::TriggerEvent(BroadcastEventDiscriminant::AnimationFrame))];
54+
const DEBUG_MESSAGE_BLOCK_LIST: &[MessageDiscriminant] = &[
55+
MessageDiscriminant::Broadcast(BroadcastMessageDiscriminant::TriggerEvent(BroadcastEventDiscriminant::AnimationFrame)),
56+
MessageDiscriminant::Animation(AnimationMessageDiscriminant::IncrementFrameCounter),
57+
];
5558
// TODO: Find a way to combine these with the list above. We use strings for now since these are the standard variant names used by multiple messages. But having these also type-checked would be best.
5659
const DEBUG_MESSAGE_ENDING_BLOCK_LIST: &[&str] = &["PointerMove", "PointerOutsideViewport", "Overlays", "Draw", "CurrentTime", "Time"];
5760

editor/src/messages/defer/defer_message.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use crate::messages::prelude::*;
33
#[impl_message(Message, Defer)]
44
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
55
pub enum DeferMessage {
6-
TriggerGraphRun,
6+
TriggerGraphRun(u64),
77
AfterGraphRun { messages: Vec<Message> },
8-
TriggerViewportResize,
9-
AfterViewportResize { messages: Vec<Message> },
8+
TriggerViewportReady,
9+
AfterViewportReady { messages: Vec<Message> },
1010
}

editor/src/messages/defer/defer_message_handler.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,28 @@ use crate::messages::prelude::*;
22

33
#[derive(Debug, Default, ExtractField)]
44
pub struct DeferMessageHandler {
5-
after_graph_run: Vec<Message>,
5+
after_graph_run: Vec<(u64, Message)>,
66
after_viewport_resize: Vec<Message>,
7+
current_graph_submission_id: u64,
78
}
89

910
#[message_handler_data]
1011
impl MessageHandler<DeferMessage, ()> for DeferMessageHandler {
1112
fn process_message(&mut self, message: DeferMessage, responses: &mut VecDeque<Message>, _: ()) {
1213
match message {
13-
DeferMessage::AfterGraphRun { messages } => {
14-
self.after_graph_run.extend_from_slice(&messages);
14+
DeferMessage::AfterGraphRun { mut messages } => {
15+
self.after_graph_run.extend(messages.drain(..).map(|m| (self.current_graph_submission_id, m)));
1516
}
16-
DeferMessage::AfterViewportResize { messages } => {
17+
DeferMessage::AfterViewportReady { messages } => {
1718
self.after_viewport_resize.extend_from_slice(&messages);
1819
}
19-
DeferMessage::TriggerGraphRun => {
20-
for message in self.after_graph_run.drain(..) {
21-
responses.push_front(message);
20+
DeferMessage::TriggerGraphRun(execution_id) => {
21+
self.current_graph_submission_id = execution_id;
22+
for message in self.after_graph_run.extract_if(.., |x| x.0 < self.current_graph_submission_id) {
23+
responses.push_front(message.1);
2224
}
2325
}
24-
DeferMessage::TriggerViewportResize => {
26+
DeferMessage::TriggerViewportReady => {
2527
for message in self.after_viewport_resize.drain(..) {
2628
responses.push_front(message);
2729
}

editor/src/messages/dialog/new_document_dialog/new_document_dialog_message_handler.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ impl MessageHandler<NewDocumentDialogMessage, ()> for NewDocumentDialogMessageHa
3636
});
3737
}
3838

39-
// TODO: Figure out how to get StartBuffer to work here so we can delete this and use `DocumentMessage::ZoomCanvasToFitAll` instead
40-
// Currently, it is necessary to use `FrontendMessage::TriggerDelayedZoomCanvasToFitAll` rather than `DocumentMessage::ZoomCanvasToFitAll` because the size of the viewport is not yet populated
41-
responses.add(DeferMessage::AfterViewportResize {
39+
responses.add(DeferMessage::AfterViewportReady {
4240
messages: vec![DocumentMessage::ZoomCanvasToFitAll.into()],
4341
});
4442
responses.add(DocumentMessage::DeselectAllLayers);

editor/src/messages/frontend/frontend_message.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ pub enum FrontendMessage {
5959
#[serde(rename = "commitDate")]
6060
commit_date: String,
6161
},
62-
TriggerDelayedZoomCanvasToFitAll,
6362
TriggerDownloadImage {
6463
svg: String,
6564
name: String,

editor/src/messages/input_preprocessor/input_preprocessor_message_handler.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ impl MessageHandler<InputPreprocessorMessage, InputPreprocessorMessageContext> f
3434
self.viewport_bounds = bounds;
3535

3636
responses.add(NavigationMessage::CanvasPan { delta: DVec2::ZERO });
37-
responses.add(DeferMessage::TriggerGraphRun);
3837
responses.add(NodeGraphMessage::SetGridAlignedEdges);
3938
}
4039
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,20 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
14351435
},
14361436
})
14371437
}
1438+
// Some parts of the editior depend on these bounds to be present
1439+
let bounds = if self.graph_view_overlay_open {
1440+
self.network_interface.all_nodes_bounding_box(&self.breadcrumb_network_path).cloned()
1441+
} else {
1442+
self.network_interface.document_bounds_document_space(true)
1443+
};
1444+
if bounds.is_some() {
1445+
responses.add(DeferMessage::TriggerViewportReady);
1446+
} else {
1447+
// If we don't have bounds yet, we need wait until the node graph has run once more
1448+
responses.add(DeferMessage::AfterGraphRun {
1449+
messages: vec![DocumentMessage::PTZUpdate.into()],
1450+
});
1451+
}
14381452
}
14391453
DocumentMessage::SelectionStepBack => {
14401454
self.network_interface.selection_step_back(&self.selection_network_path);

editor/src/messages/portfolio/portfolio_message_handler.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -702,13 +702,12 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio
702702

703703
if create_document {
704704
// Wait for the document to be rendered so the click targets can be calculated in order to determine the artboard size that will encompass the pasted image
705+
responses.add(DeferMessage::AfterViewportReady {
706+
messages: vec![DocumentMessage::ZoomCanvasToFitAll.into()],
707+
});
705708
responses.add(DeferMessage::AfterGraphRun {
706709
messages: vec![DocumentMessage::WrapContentInArtboard { place_artboard_at_origin: true }.into()],
707710
});
708-
709-
responses.add(DeferMessage::AfterViewportResize {
710-
messages: vec![DocumentMessage::ZoomCanvasToFitAll.into()],
711-
});
712711
}
713712
}
714713
PortfolioMessage::PasteSvg {
@@ -738,7 +737,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio
738737
messages: vec![DocumentMessage::WrapContentInArtboard { place_artboard_at_origin: true }.into()],
739738
});
740739

741-
responses.add(DeferMessage::AfterViewportResize {
740+
responses.add(DeferMessage::AfterViewportReady {
742741
messages: vec![DocumentMessage::ZoomCanvasToFitAll.into()],
743742
});
744743
}
@@ -1020,7 +1019,6 @@ impl PortfolioMessageHandler {
10201019
/text>"#
10211020
// It's a mystery why the `/text>` tag above needs to be missing its `<`, but when it exists it prints the `<` character in the text. However this works with it removed.
10221021
.to_string();
1023-
responses.add(DeferMessage::TriggerGraphRun);
10241022
responses.add(FrontendMessage::UpdateDocumentArtwork { svg: error });
10251023
}
10261024
result

editor/src/messages/tool/tool_messages/pen_tool.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,9 +1721,9 @@ impl Fsm for PenToolFsmState {
17211721
let next_point = tool_data.next_point;
17221722
let start = latest_point.id;
17231723

1724-
if let Some(layer) = layer {
1725-
let mut vector_data = document.network_interface.compute_modified_vector(layer).unwrap();
1726-
1724+
if let Some(layer) = layer
1725+
&& let Some(mut vector_data) = document.network_interface.compute_modified_vector(layer)
1726+
{
17271727
let closest_point = vector_data.extendable_points(preferences.vector_meshes).filter(|&id| id != start).find(|&id| {
17281728
vector_data.point_domain.position_from_id(id).map_or(false, |pos| {
17291729
let dist_sq = transform.transform_point2(pos).distance_squared(transform.transform_point2(next_point));

editor/src/node_graph_executor.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::messages::frontend::utility_types::{ExportBounds, FileType};
33
use crate::messages::prelude::*;
44
use glam::{DAffine2, DVec2, UVec2};
55
use graph_craft::document::value::{RenderOutput, TaggedValue};
6-
use graph_craft::document::{DocumentNode, DocumentNodeImplementation, NodeId, NodeInput, generate_uuid};
6+
use graph_craft::document::{DocumentNode, DocumentNodeImplementation, NodeId, NodeInput};
77
use graph_craft::proto::GraphErrors;
88
use graph_craft::wasm_application_io::EditorPreferences;
99
use graphene_std::application_io::TimingInformation;
@@ -56,6 +56,7 @@ pub enum NodeGraphUpdate {
5656
#[derive(Debug, Default)]
5757
pub struct NodeGraphExecutor {
5858
runtime_io: NodeRuntimeIO,
59+
current_execution_id: u64,
5960
futures: HashMap<u64, ExecutionContext>,
6061
node_graph_hash: u64,
6162
old_inspect_node: Option<NodeId>,
@@ -78,13 +79,15 @@ impl NodeGraphExecutor {
7879
futures: Default::default(),
7980
runtime_io: NodeRuntimeIO::with_channels(request_sender, response_receiver),
8081
node_graph_hash: 0,
82+
current_execution_id: 0,
8183
old_inspect_node: None,
8284
};
8385
(node_runtime, node_executor)
8486
}
8587
/// Execute the network by flattening it and creating a borrow stack.
86-
fn queue_execution(&self, render_config: RenderConfig) -> u64 {
87-
let execution_id = generate_uuid();
88+
fn queue_execution(&mut self, render_config: RenderConfig) -> u64 {
89+
let execution_id = self.current_execution_id;
90+
self.current_execution_id += 1;
8891
let request = ExecutionRequest { execution_id, render_config };
8992
self.runtime_io.send(GraphRuntimeRequest::ExecutionRequest(request)).expect("Failed to send generation request");
9093

@@ -105,7 +108,7 @@ impl NodeGraphExecutor {
105108
#[cfg(test)]
106109
pub(crate) fn update_node_graph_instrumented(&mut self, document: &mut DocumentMessageHandler) -> Result<Instrumented, String> {
107110
// We should always invalidate the cache.
108-
self.node_graph_hash = generate_uuid();
111+
self.node_graph_hash = crate::application::generate_uuid();
109112
let mut network = document.network_interface.document_network().clone();
110113
let instrumented = Instrumented::new(&mut network);
111114

@@ -280,6 +283,7 @@ impl NodeGraphExecutor {
280283
} else {
281284
self.process_node_graph_output(node_graph_output, transform, responses)?
282285
}
286+
responses.add(DeferMessage::TriggerGraphRun(execution_id));
283287

284288
// Update the spreadsheet on the frontend using the value of the inspect result.
285289
if self.old_inspect_node.is_some() {
@@ -384,7 +388,6 @@ impl NodeGraphExecutor {
384388
return Err(format!("Invalid node graph output type: {node_graph_output:#?}"));
385389
}
386390
};
387-
responses.add(DeferMessage::TriggerGraphRun);
388391
let graphene_std::renderer::RenderMetadata {
389392
upstream_footprints: footprints,
390393
local_transforms,

0 commit comments

Comments
 (0)