From b81479cc8811bfa39f40f5fd21c8231c170e8f65 Mon Sep 17 00:00:00 2001 From: nekomehako Date: Wed, 11 May 2022 01:56:34 +0900 Subject: [PATCH] Fix a crash bug when deleting an active node --- egui_node_graph_example/src/app.rs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/egui_node_graph_example/src/app.rs b/egui_node_graph_example/src/app.rs index ac60aba..9c1fb76 100644 --- a/egui_node_graph_example/src/app.rs +++ b/egui_node_graph_example/src/app.rs @@ -376,17 +376,21 @@ impl epi::App for NodeGraphExample { } if let Some(node) = self.state.user_state.active_node { - let text = match evaluate_node(&self.state.graph, node, &mut HashMap::new()) { - Ok(value) => format!("The result is: {:?}", value), - Err(err) => format!("Execution error: {}", err), - }; - ctx.debug_painter().text( - egui::pos2(10.0, 10.0), - egui::Align2::LEFT_TOP, - text, - egui::TextStyle::Button, - egui::Color32::WHITE, - ); + if self.state.graph.nodes.contains_key(node) { + let text = match evaluate_node(&self.state.graph, node, &mut HashMap::new()) { + Ok(value) => format!("The result is: {:?}", value), + Err(err) => format!("Execution error: {}", err), + }; + ctx.debug_painter().text( + egui::pos2(10.0, 10.0), + egui::Align2::LEFT_TOP, + text, + egui::TextStyle::Button, + egui::Color32::WHITE, + ); + } else { + self.state.user_state.active_node = None; + } } } }