From dd3d1f3dd70b25fff0f0aa4c736b9a3243b5c750 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 12 Sep 2024 22:34:32 +0200 Subject: [PATCH] TestEngine: fixed a crash when item/window stops being submitted (or test is aborted) in the middle of a MouseMove() action performing a long scroll. --- docs/CHANGELOG.txt | 4 ++++ imgui_test_engine/imgui_te_context.cpp | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 7a7323c..beed55e 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -5,6 +5,10 @@ CHANGELOG Those changes are not all listed here. ** For a while this is going to ONLY INCLUDE BREAKING CHANGES. +2024/09/12: +- TestEngine: fixed a crash when item/window stops being submitted (or test is aborted) + in the middle of a MouseMove() action performing a long scroll. + 2024/09/10: - TestEngine: CaptureTool: rename ImGuiCaptureFlags_IncludeTooltipsAndPopups to ImGuiCaptureFlags_IncludePopups, as tooltips are always included by default in the capture. diff --git a/imgui_test_engine/imgui_te_context.cpp b/imgui_test_engine/imgui_te_context.cpp index 1e6a00e..b07de2f 100644 --- a/imgui_test_engine/imgui_te_context.cpp +++ b/imgui_test_engine/imgui_te_context.cpp @@ -1700,13 +1700,14 @@ void ImGuiTestContext::MouseMove(ImGuiTestRef ref, ImGuiTestOpFlags flags) float extra_width_desired = item.RectFull.Max.x - window_r.Max.x; // item->RectClipped.Max.x; if (extra_width_desired > 0.0f && (flags & ImGuiTestOpFlags_IsSecondAttempt) == 0) { - LogDebug("Will attempt to resize window to make item in menu layer visible."); + LogDebug("MouseMove: Will attempt to resize window to make item in menu layer visible."); WindowResize(window->ID, window->Size + ImVec2(extra_width_desired, 0.0f)); } } } // Update item + ImGuiTestItemInfo old_item = item; item = ItemInfo(item.ID); // FIXME-TESTS-NOT_SAME_AS_END_USER @@ -1714,6 +1715,13 @@ void ImGuiTestContext::MouseMove(ImGuiTestRef ref, ImGuiTestOpFlags flags) if (WindowTeleportToMakePosVisible(window->ID, pos)) item = ItemInfo(item.ID); + // Handle the off-chance that e.g. item/window stops being submitted while scrolling (easy to repro by pressing Esc during a long scroll) + if (item.ID == 0) + { + LogError("MouseMove: item doesn't exist anymore (after scrolling)"); + return; + } + // Keep a copy of item info const ImGuiTestItemInfo item_initial_state = item; @@ -1742,7 +1750,7 @@ void ImGuiTestContext::MouseMove(ImGuiTestRef ref, ImGuiTestOpFlags flags) // Another is window active test (in the case focus change has a side effect but also as we have yield an extra frame) if (!item.Window->WasActive) { - LogError("Window '%s' is not active (after aiming)", item.Window->Name); + LogError("MouseMove: Window '%s' is not active (after aiming)", item.Window->Name); return; } @@ -1797,7 +1805,7 @@ void ImGuiTestContext::MouseMove(ImGuiTestRef ref, ImGuiTestOpFlags flags) is_hovering_resize_corner |= (hovered_id == ImGui::GetWindowResizeCornerID(window, n)); if (is_hovering_resize_corner) { - LogDebug("Child obstructed by parent's ResizeGrip, trying to resize window and trying again.."); + LogDebug("MouseMove: Child obstructed by parent's ResizeGrip, trying to resize window and trying again.."); float extra_size = window->CalcFontSize() * 3.0f; WindowResize(window->ID, window->Size + ImVec2(extra_size, extra_size)); MouseMove(ref, flags | ImGuiTestOpFlags_IsSecondAttempt); @@ -1815,7 +1823,7 @@ void ImGuiTestContext::MouseMove(ImGuiTestRef ref, ImGuiTestOpFlags flags) ImVec2 size_old = item_initial_state.RectFull.GetSize(); ImVec2 size_new = item.RectFull.GetSize(); Str256f error_message( - "Unable to Hover %s:\n" + "MouseMove: Unable to Hover %s:\n" "- Expected item 0x%08X in window '%s', targeted position: (%.1f,%.1f)'\n" "- Hovered id was 0x%08X in '%s'.\n" "- Before mouse move: Item Pos (%6.1f,%6.1f) Size (%6.1f,%6.1f)\n"