From 33892c1936f4033ec80c811e97478b3183f7bcde Mon Sep 17 00:00:00 2001 From: maj00r Date: Mon, 19 Oct 2026 20:02:03 +0200 Subject: [PATCH] fix(editor): a touchpad swipe going on past the edge of the window no longer throws the camera away With the cursor out of the window ImGui has no place for it, and the ray under it came out as NaN: the zoom put the camera there for good and the next look at the ground under the cursor aborted. The wheel is left alone then, and the ground isn't asked for a point which isn't one. The self-test gets leave, the cursor taken out of the window. --- application/editormode.cpp | 5 ++++- application/scriptedinput.cpp | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/application/editormode.cpp b/application/editormode.cpp index a1cac045..cd665ef9 100644 --- a/application/editormode.cpp +++ b/application/editormode.cpp @@ -3350,6 +3350,8 @@ glm::dvec3 editor_mode::placement_on_ground(glm::dvec3 Location) double constexpr height_tolerance = 50.0; // with nothing there or lower, how far up the ground is looked for float constexpr terrain_model_radius = 50.0f; // the same models count as ground as for the area fill and the orthophoto + if (false == std::isfinite(Location.x) || false == std::isfinite(Location.y) || false == std::isfinite(Location.z)) + return Location; glm::dvec2 const bmin{Location.x - reach, Location.z - reach}; glm::dvec2 const bmax{Location.x + reach, Location.z + reach}; std::vector triangles; @@ -5884,7 +5886,8 @@ void editor_mode::on_scroll(double const Xoffset, double const Yoffset) { if (false == ImGui::GetIO().WantCaptureMouse && track_wheel(Yoffset != 0.0 ? Yoffset : Xoffset)) return; - if (ImGui::GetIO().WantCaptureMouse || Yoffset == 0.0) + // a swipe on a touchpad goes on after the cursor left the window, with no place for the ray under it + if (ImGui::GetIO().WantCaptureMouse || Yoffset == 0.0 || false == ImGui::IsMousePosValid()) return; // a fast swipe on a touchpad can come as one big step auto const notches{std::clamp(Yoffset, -2.0, 2.0)}; diff --git a/application/scriptedinput.cpp b/application/scriptedinput.cpp index 5b505936..e94b752b 100644 --- a/application/scriptedinput.cpp +++ b/application/scriptedinput.cpp @@ -93,6 +93,13 @@ bool scripted_input::dispatch(std::string const &Command, std::istringstream &Wo WriteLog(format("SELFTEST mouse %.0f %.0f", screen.x, screen.y)); return true; } + if (Command == "leave") + { + m_mouse.reset(); + queue([]() { ui_layer::cursor_enter_callback(0); }); + WriteLog("SELFTEST leave"); + return true; + } if (Command == "button") { std::string which;