egui_graphs icon indicating copy to clipboard operation
egui_graphs copied to clipboard

unwrap panic in graph.rs, `edge_by_screen_pos`

Open XertroV opened this issue 1 year ago • 1 comments

edge_by_screen_pos panics if you are clicking and holding a node while extending the graph. Seems to be because self.g.edge_endpoints(e.id()) returns None.

The following seems to work as a fix, but not sure if this is a bigger bug.

    pub fn edge_by_screen_pos(&self, meta: &Metadata, screen_pos: Pos2) -> Option<EdgeIndex<Ix>> {
        let pos_in_graph = meta.screen_to_canvas_pos(screen_pos);
        for (idx, e) in self.edges_iter() {
            let (idx_start, idx_end) = match self.g.edge_endpoints(e.id()) {
                Some((start, end)) => (start, end),
                None => continue,
            };
            let start = self.g.node_weight(idx_start).unwrap();
            let end = self.g.node_weight(idx_end).unwrap();
            if e.display().is_inside(start, end, pos_in_graph) {
                return Some(idx);
            }
        }

        None
    }

XertroV avatar Feb 02 '24 03:02 XertroV

I am not sure if this is reproducable during the intended usage.

blitzarx1 avatar Feb 24 '24 11:02 blitzarx1