Merge pull request #24 from kkngsm/active-node

Fix a crash bug when deleting an active node
This commit is contained in:
setzer22 2022-05-24 11:54:56 +02:00 committed by GitHub
commit 24036d1294
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -357,7 +357,9 @@ impl eframe::App for NodeGraphExample {
.show(ctx, |ui| { .show(ctx, |ui| {
self.state.draw_graph_editor(ui, AllMyNodeTemplates) self.state.draw_graph_editor(ui, AllMyNodeTemplates)
}) })
.unwrap().inner.unwrap(); .unwrap()
.inner
.unwrap();
for node_response in graph_response.node_responses { for node_response in graph_response.node_responses {
// Here, we ignore all other graph events. But you may find // Here, we ignore all other graph events. But you may find
// some use for them. For example, by playing a sound when a new // some use for them. For example, by playing a sound when a new
@ -373,17 +375,21 @@ impl eframe::App for NodeGraphExample {
} }
if let Some(node) = self.state.user_state.active_node { if let Some(node) = self.state.user_state.active_node {
let text = match evaluate_node(&self.state.graph, node, &mut HashMap::new()) { if self.state.graph.nodes.contains_key(node) {
Ok(value) => format!("The result is: {:?}", value), let text = match evaluate_node(&self.state.graph, node, &mut HashMap::new()) {
Err(err) => format!("Execution error: {}", err), Ok(value) => format!("The result is: {:?}", value),
}; Err(err) => format!("Execution error: {}", err),
ctx.debug_painter().text( };
egui::pos2(10.0, 10.0), ctx.debug_painter().text(
egui::Align2::LEFT_TOP, egui::pos2(10.0, 10.0),
text, egui::Align2::LEFT_TOP,
TextStyle::Button.resolve(&ctx.style()), text,
egui::Color32::WHITE, TextStyle::Button.resolve(&ctx.style()),
); egui::Color32::WHITE,
);
} else {
self.state.user_state.active_node = None;
}
} }
} }
} }