From f6890ed007da2efee80a91f140bcb57a68811c22 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 17 Sep 2025 16:34:33 +0200 Subject: [PATCH] Nav, Inputs: fixed a crash that could occur when opening a popup following the processing of a global shortcut while no windows were focused. Regression test: "window_popup_from_shortcut" --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 9495d5af1..b1575131c 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -54,6 +54,8 @@ Other Changes: e.g. using clipper with ItemsHeight=1 in order to clip in pixel units. (#8886) - Nav: fixed Ctrl+Tab window appearing as empty when the sole active and focused window has the ImGuiWindowFlags_NoNavFocus flag. (#8914) +- Nav: fixed a crash that could occur when opening a popup following the processing + of a global shortcut while no windows were focused. - Bullet: fixed tesselation amount which looked out of place in very large sizes. - InputText: added ImGuiInputTextFlags_WordWrap flag to word-wrap multi-line buffers. (#3237, #952, #1062, #7363). Current caveats: diff --git a/imgui.cpp b/imgui.cpp index eb84cdd4c..514f1ecdc 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -13413,6 +13413,9 @@ static ImVec2 ImGui::NavCalcPreferredRefPos() const bool activated_shortcut = g.ActiveId != 0 && g.ActiveIdFromShortcut && g.ActiveId == g.LastItemData.ID; + if (source != ImGuiInputSource_Mouse && !activated_shortcut && window == NULL) + source = ImGuiInputSource_Mouse; + // Testing for !activated_shortcut here could in theory be removed if we decided that activating a remote shortcut altered one of the g.NavDisableXXX flag. if (source == ImGuiInputSource_Mouse) { @@ -13432,7 +13435,7 @@ static ImVec2 ImGui::NavCalcPreferredRefPos() ref_rect = WindowRectRelToAbs(window, window->NavRectRel[g.NavLayer]); // Take account of upcoming scrolling (maybe set mouse pos should be done in EndFrame?) - if (window->LastFrameActive != g.FrameCount && (window->ScrollTarget.x != FLT_MAX || window->ScrollTarget.y != FLT_MAX)) + if (window != NULL && window->LastFrameActive != g.FrameCount && (window->ScrollTarget.x != FLT_MAX || window->ScrollTarget.y != FLT_MAX)) { ImVec2 next_scroll = CalcNextScrollFromScrollTargetAndClamp(window); ref_rect.Translate(window->Scroll - next_scroll);