Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unwrap panic in graph.rs, edge_by_screen_pos #166

Closed
XertroV opened this issue Feb 2, 2024 · 1 comment
Closed

unwrap panic in graph.rs, edge_by_screen_pos #166

XertroV opened this issue Feb 2, 2024 · 1 comment

Comments

@XertroV
Copy link
Contributor

XertroV commented Feb 2, 2024

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
    }
@blitzarx1
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants