Error handling: Improve error handling and recovery for EndMenu()/EndCombo(). (#1651, #9165, #8499)

This commit is contained in:
ocornut
2026-01-14 14:59:39 +01:00
parent 791ad9b82d
commit 0d08927dae
3 changed files with 18 additions and 4 deletions
+2
View File
@@ -173,6 +173,8 @@ Other Changes:
(which mimicks what's done internally in the ItemHoverable() function). (#9138) (which mimicks what's done internally in the ItemHoverable() function). (#9138)
- Fixed tooltip placement being affected for a frame when located over an item - Fixed tooltip placement being affected for a frame when located over an item
activated by SetNextItemShortcut(). (#9138) activated by SetNextItemShortcut(). (#9138)
- Error Handling:
- Improve error handling and recovery for EndMenu()/EndCombo(). (#1651, #9165, #8499)
- Debug Tools: - Debug Tools:
- Debug Log: fixed incorrectly printing characters in IO log when submitting - Debug Log: fixed incorrectly printing characters in IO log when submitting
non-ASCII values to io.AddInputCharacter(). (#9099) non-ASCII values to io.AddInputCharacter(). (#9099)
+1 -1
View File
@@ -12455,7 +12455,7 @@ void ImGui::EndPopup()
ImGuiWindow* window = g.CurrentWindow; ImGuiWindow* window = g.CurrentWindow;
if ((window->Flags & ImGuiWindowFlags_Popup) == 0 || g.BeginPopupStack.Size == 0) if ((window->Flags & ImGuiWindowFlags_Popup) == 0 || g.BeginPopupStack.Size == 0)
{ {
IM_ASSERT_USER_ERROR(0, "Calling EndPopup() too many times or in wrong window!"); IM_ASSERT_USER_ERROR(0, "Calling EndPopup() in wrong window!");
return; return;
} }
+15 -3
View File
@@ -2053,8 +2053,15 @@ bool ImGui::BeginComboPopup(ImGuiID popup_id, const ImRect& bb, ImGuiComboFlags
void ImGui::EndCombo() void ImGui::EndCombo()
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
EndPopup();
g.BeginComboDepth--; g.BeginComboDepth--;
char name[16];
ImFormatString(name, IM_COUNTOF(name), "##Combo_%02d", g.BeginComboDepth); // FIXME: Move those to helpers?
if (strcmp(g.CurrentWindow->Name, name) != 0)
{
IM_ASSERT_USER_ERROR(0, "Calling EndCombo() in wrong window!");
return;
}
EndPopup();
} }
// Call directly after the BeginCombo/EndCombo block. The preview is designed to only host non-interactive elements // Call directly after the BeginCombo/EndCombo block. The preview is designed to only host non-interactive elements
@@ -9399,7 +9406,12 @@ void ImGui::EndMenu()
// Nav: When a left move request our menu failed, close ourselves. // Nav: When a left move request our menu failed, close ourselves.
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow; ImGuiWindow* window = g.CurrentWindow;
IM_ASSERT(window->Flags & ImGuiWindowFlags_Popup); // Mismatched BeginMenu()/EndMenu() calls
if ((window->Flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_ChildMenu)) != (ImGuiWindowFlags_Popup | ImGuiWindowFlags_ChildMenu))
{
IM_ASSERT_USER_ERROR(0, "Calling EndMenu() in wrong window!");
return;
}
ImGuiWindow* parent_window = window->ParentWindow; // Should always be != NULL is we passed assert. ImGuiWindow* parent_window = window->ParentWindow; // Should always be != NULL is we passed assert.
if (window->BeginCount == window->BeginCountPreviousFrame) if (window->BeginCount == window->BeginCountPreviousFrame)
if (g.NavMoveDir == ImGuiDir_Left && NavMoveRequestButNoResultYet()) if (g.NavMoveDir == ImGuiDir_Left && NavMoveRequestButNoResultYet())
@@ -10343,7 +10355,7 @@ bool ImGui::BeginTabItem(const char* label, bool* p_open, ImGuiTabItemFlags f
ImGuiTabBar* tab_bar = g.CurrentTabBar; ImGuiTabBar* tab_bar = g.CurrentTabBar;
if (tab_bar == NULL) if (tab_bar == NULL)
{ {
IM_ASSERT_USER_ERROR(tab_bar, "Needs to be called between BeginTabBar() and EndTabBar()!"); IM_ASSERT_USER_ERROR(tab_bar != NULL, "Needs to be called between BeginTabBar() and EndTabBar()!");
return false; return false;
} }
IM_ASSERT((flags & ImGuiTabItemFlags_Button) == 0); // BeginTabItem() Can't be used with button flags, use TabItemButton() instead! IM_ASSERT((flags & ImGuiTabItemFlags_Button) == 0); // BeginTabItem() Can't be used with button flags, use TabItemButton() instead!