From ae21315593d80c962b2eea519e78327d92fa26aa Mon Sep 17 00:00:00 2001
From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr>
Date: Fri, 5 Apr 2024 11:15:09 +0200
Subject: [PATCH] Network: Fix crash when edge addition click on the void.

---
 src/View/Network/GraphWidget.py | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/View/Network/GraphWidget.py b/src/View/Network/GraphWidget.py
index 3fbc96d9..2d96617b 100644
--- a/src/View/Network/GraphWidget.py
+++ b/src/View/Network/GraphWidget.py
@@ -624,11 +624,18 @@ class GraphWidget(QGraphicsView):
         Returns:
             Nothing
         """
-        previous_node = self._selected_new_edge_src_node
-        self._selected_new_edge_src_node = node
+        try:
+            previous_node = self._selected_new_edge_src_node
+            self._selected_new_edge_src_node = node
+
+            if node is None:
+                if self.tmp_line is not None:
+                    self.tmp_line = None
 
-        if previous_node:
-            previous_node.update()
+            if previous_node is not None:
+                previous_node.update()
+        except Exception as e:
+            logger.warning(str(e))
 
     def current_edge(self):
         """The current selected edge
@@ -732,6 +739,7 @@ class GraphWidget(QGraphicsView):
             nodes = list(filter(lambda i: type(i) is NodeItem, items))
             if not nodes:
                 self.add_node(pos)
+                self.set_selected_new_edge_src_node(None)
             else:
                 if self.selected_new_edge_src_node() is None:
                     self.set_selected_new_edge_src_node(nodes[0])
-- 
GitLab