1
0
Fork 0
mirror of https://github.com/ocornut/imgui.git synced 2026-01-22 01:54:21 +00:00

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

View file

@ -173,6 +173,8 @@ Other Changes:
(which mimicks what's done internally in the ItemHoverable() function). (#9138)
- Fixed tooltip placement being affected for a frame when located over an item
activated by SetNextItemShortcut(). (#9138)
- Error Handling:
- Improve error handling and recovery for EndMenu()/EndCombo(). (#1651, #9165, #8499)
- Debug Tools:
- Debug Log: fixed incorrectly printing characters in IO log when submitting
non-ASCII values to io.AddInputCharacter(). (#9099)

View file

@ -12455,7 +12455,7 @@ void ImGui::EndPopup()
ImGuiWindow* window = g.CurrentWindow;
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;
}

View file

@ -2053,8 +2053,15 @@ bool ImGui::BeginComboPopup(ImGuiID popup_id, const ImRect& bb, ImGuiComboFlags
void ImGui::EndCombo()
{
ImGuiContext& g = *GImGui;
EndPopup();
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
@ -9399,7 +9406,12 @@ void ImGui::EndMenu()
// Nav: When a left move request our menu failed, close ourselves.
ImGuiContext& g = *GImGui;
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.
if (window->BeginCount == window->BeginCountPreviousFrame)
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;
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;
}
IM_ASSERT((flags & ImGuiTabItemFlags_Button) == 0); // BeginTabItem() Can't be used with button flags, use TabItemButton() instead!