From b62664ad33546ae27876ea57e079c87cba346ff1 Mon Sep 17 00:00:00 2001 From: Nigel Ihza Firdausy <106657905+Ni-zav@users.noreply.github.com> Date: Thu, 8 Oct 2026 04:57:33 +0700 Subject: [PATCH] fix(ui): cancel stale warp drags when the mesh changes (#757) (#774) --- crates/ui-egui/src/transform_tool.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/crates/ui-egui/src/transform_tool.rs b/crates/ui-egui/src/transform_tool.rs index 09586d7cf5b..dbc1cca52e8 100644 --- a/crates/ui-egui/src/transform_tool.rs +++ b/crates/ui-egui/src/transform_tool.rs @@ -1019,6 +1019,11 @@ pub fn edit_session_warp(app: &mut PhotocraftApp, id: &str, params: &serde_json: let r = app.session.execute(id, p).map_err(|e| e.to_string())?; let raw = r.get("warp").cloned().ok_or_else(|| "warp command returned no mesh".to_string())?; let nw: Warp = serde_json::from_value(raw).map_err(|e| e.to_string())?; + // A warp-edit command can replace the mesh while pointer input is split across control + // requests. Any drag index captured from the old mesh is invalid once that happens. + if let Some(pv) = app.transform_preview.as_mut() { + pv.warp_drag = None; + } if let Some(t) = app.ui.transform.as_mut() { t.warp = Some(nw); } @@ -2093,6 +2098,25 @@ mod tests { assert!(app.ui.transform.as_ref().unwrap().warp.is_none()); } + #[test] + fn replacing_the_warp_mesh_cancels_a_pending_point_drag() { + let mut app = app_with_square(64, photocraft_geom::Rect::new(8, 8, 32, 32)); + let ctx = egui::Context::default(); + begin_warp(&mut app, &ctx).unwrap(); + for _ in 0..3 { + split(&mut app, "edit.transform.splitWarpCrosswise", None).unwrap(); + } + + pointer(&mut app, ToolEvent::Down { x: 32.0, y: 32.0, pressure: 1.0 }, egui::Modifiers::NONE); + assert!(app.transform_preview.as_ref().unwrap().warp_drag.is_some(), "the anchor drag is armed"); + + split(&mut app, "edit.transform.removeWarpSplit", None).unwrap(); + assert!(app.transform_preview.as_ref().unwrap().warp_drag.is_none(), "the old mesh index is discarded"); + + // A later control-channel move belongs to the old gesture and must be harmless. + pointer(&mut app, ToolEvent::Move { x: 40.0, y: 40.0, pressure: 1.0 }, egui::Modifiers::NONE); + } + /// A press on a preset warp that misses its points leaves the preset alone (no invisible undo /// step); grabbing a point turns it into a custom mesh. #[test]