Skip to content

Commit

Permalink
TestEngine: fixed a crash when item/window stops being submitted (or …
Browse files Browse the repository at this point in the history
…test is aborted) in the middle of a MouseMove() action performing a long scroll.
  • Loading branch information
ocornut committed Sep 12, 2024
1 parent fa4986c commit dd3d1f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 12 additions & 4 deletions imgui_test_engine/imgui_te_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1700,20 +1700,28 @@ 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
ImVec2 pos = item.RectFull.GetCenter();
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;

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand All @@ -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"
Expand Down

0 comments on commit dd3d1f3

Please sign in to comment.