@@ -1426,13 +1426,15 @@ namespace pythonic
14261426 // Retrieve original edge IDs from the snapshot index under lock
14271427 size_t orig_u = (size_t )-1 ;
14281428 size_t orig_v = (size_t )-1 ;
1429-
1429+
14301430 {
14311431 std::lock_guard<std::mutex> lock (snapshot_mutex_);
14321432 // This ensures we remove the ACTUAL existing edge, not the potentially-swapped UI values
1433- if (last_selected_edge_idx_ >= 0 && last_selected_edge_idx_ < back_snapshot_.edges .size ()) {
1434- const auto & es = back_snapshot_.edges [last_selected_edge_idx_];
1435- if (es.from < back_snapshot_.nodes .size () && es.to < back_snapshot_.nodes .size ()) {
1433+ if (last_selected_edge_idx_ >= 0 && last_selected_edge_idx_ < back_snapshot_.edges .size ())
1434+ {
1435+ const auto &es = back_snapshot_.edges [last_selected_edge_idx_];
1436+ if (es.from < back_snapshot_.nodes .size () && es.to < back_snapshot_.nodes .size ())
1437+ {
14361438 orig_u = back_snapshot_.nodes [es.from ].node_id ;
14371439 orig_v = back_snapshot_.nodes [es.to ].node_id ;
14381440 }
@@ -1447,7 +1449,7 @@ namespace pythonic
14471449 // Remove original edge(s) completely to avoid duplicates/residue
14481450 graph_var_.remove_edge (orig_u, orig_v, true );
14491451 graph_var_.remove_edge (orig_v, orig_u, true );
1450-
1452+
14511453 if (directed)
14521454 graph_var_.add_edge (selected_edge_node_from_id_, selected_edge_node_to_id_, w1, std::numeric_limits<double >::quiet_NaN (), true );
14531455 else
@@ -1467,12 +1469,14 @@ namespace pythonic
14671469 // Use original IDs for removal to ensure it works even if UI was flipped
14681470 size_t orig_u = (size_t )-1 ;
14691471 size_t orig_v = (size_t )-1 ;
1470-
1472+
14711473 {
14721474 std::lock_guard<std::mutex> lock (snapshot_mutex_);
1473- if (last_selected_edge_idx_ >= 0 && last_selected_edge_idx_ < back_snapshot_.edges .size ()) {
1474- const auto & es = back_snapshot_.edges [last_selected_edge_idx_];
1475- if (es.from < back_snapshot_.nodes .size () && es.to < back_snapshot_.nodes .size ()) {
1475+ if (last_selected_edge_idx_ >= 0 && last_selected_edge_idx_ < back_snapshot_.edges .size ())
1476+ {
1477+ const auto &es = back_snapshot_.edges [last_selected_edge_idx_];
1478+ if (es.from < back_snapshot_.nodes .size () && es.to < back_snapshot_.nodes .size ())
1479+ {
14761480 orig_u = back_snapshot_.nodes [es.from ].node_id ;
14771481 orig_v = back_snapshot_.nodes [es.to ].node_id ;
14781482 }
@@ -2158,8 +2162,10 @@ namespace pythonic
21582162 {
21592163 size_t node_id = static_cast <size_t >(path_var[i].toInt ());
21602164 // Map node_id to snapshot index
2161- for (size_t idx = 0 ; idx < back_snapshot_.nodes .size (); ++idx) {
2162- if (back_snapshot_.nodes [idx].node_id == node_id) {
2165+ for (size_t idx = 0 ; idx < back_snapshot_.nodes .size (); ++idx)
2166+ {
2167+ if (back_snapshot_.nodes [idx].node_id == node_id)
2168+ {
21632169 sp_path_indices_.push_back (idx);
21642170 break ;
21652171 }
@@ -2282,9 +2288,14 @@ namespace pythonic
22822288 running_ = true ;
22832289
22842290 // RAII guard to ensure physics thread stops even on exception
2285- struct PhysicsGuard {
2286- GraphViewer::Impl* impl;
2287- ~PhysicsGuard () { impl->stop_physics (); impl->running_ = false ; }
2291+ struct PhysicsGuard
2292+ {
2293+ GraphViewer::Impl *impl;
2294+ ~PhysicsGuard ()
2295+ {
2296+ impl->stop_physics ();
2297+ impl->running_ = false ;
2298+ }
22882299 } guard{this };
22892300
22902301 while (!glfwWindowShouldClose (window_) && !close_requested_)
0 commit comments