From 3883a2027f77304cb2d72ea7495789420e567b41 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 21 Aug 2016 17:52:42 +0200 Subject: [PATCH] Nav: Fixed Selectable() crash introduced earlier today in 43ee5d73 + added comments/assert (#323) --- imgui.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index f34e319f..f528568f 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2347,6 +2347,7 @@ int ImGui::GetFrameCount() static void SetNavId(ImGuiID id) { ImGuiContext& g = *GImGui; + IM_ASSERT(g.NavWindow); g.NavId = id; if (g.NavLayer == 0) g.NavWindow->NavLastId = g.NavId; @@ -9503,7 +9504,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl selected = false; // Hovering selectable with mouse updates NavId accordingly so navigation can be resumed with gamepad/keyboard (this doesn't happen on most widgets) - if (hovered && !g.NavDisableMouseHover && (g.IO.MouseDelta.x != 0.0f || g.IO.MouseDelta.y != 0.0f)) + if (hovered && !g.NavDisableMouseHover && g.NavWindow == window && (g.IO.MouseDelta.x != 0.0f || g.IO.MouseDelta.y != 0.0f)) { g.NavDisableHighlight = true; SetNavId(id); @@ -9756,7 +9757,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled) bool menuset_is_open = !(window->Flags & ImGuiWindowFlags_Popup) && (g.OpenPopupStack.Size > g.CurrentPopupStack.Size && g.OpenPopupStack[g.CurrentPopupStack.Size].ParentMenuSet == window->GetID("##menus")); ImGuiWindow* backed_nav_window = g.NavWindow; if (menuset_is_open) - g.NavWindow = window; + g.NavWindow = window; // Odd hack to allow hovering across menus of a same menu-set (otherwise we wouldn't be able to hover parent) ImVec2 popup_pos, pos = window->DC.CursorPos; if (window->DC.LayoutType == ImGuiLayoutType_Horizontal)