Skip to content

Commit 9038678

Browse files
committed
Misc: Fixed calling GetID("label") _before_ a widget emitting this item inside a group (such as InputInt()) from causing an assertion when closing the group. (ocornut#5181).
1 parent 937d073 commit 9038678

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

docs/CHANGELOG.txt

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ Other Changes:
7575
- Stack Tool: Added option to copy item path to clipboard. (#4631)
7676
- Drawlist: Fixed PathArcTo() emitting terminating vertices too close to arc vertices. (#4993) [@thedmd]
7777
- DrawList: Fixed texture-based anti-aliasing path with RGBA textures (#5132, #3245) [@cfillion]
78+
- Misc: Fixed calling GetID("label") _before_ a widget emitting this item inside a group (such as InputInt())
79+
from causing an assertion when closing the group. (#5181).
7880
- Misc: Fixed IsAnyItemHovered() returning false when using navigation.
7981
- Misc: Added IMGUI_STB_SPRINTF_FILENAME to support custom path to stb_sprintf. (#5068, #2954) [@jakubtomsu]
8082
- Misc: Added constexpr to ImVec2/ImVec4 inline constructors. (#4995) [@Myriachan]

imgui.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -3268,7 +3268,6 @@ ImGuiID ImGuiWindow::GetID(const char* str, const char* str_end)
32683268
{
32693269
ImGuiID seed = IDStack.back();
32703270
ImGuiID id = ImHashStr(str, str_end ? (str_end - str) : 0, seed);
3271-
ImGui::KeepAliveID(id);
32723271
ImGuiContext& g = *GImGui;
32733272
if (g.DebugHookIdInfo == id)
32743273
ImGui::DebugHookIdInfo(id, ImGuiDataType_String, str, str_end);
@@ -3279,7 +3278,6 @@ ImGuiID ImGuiWindow::GetID(const void* ptr)
32793278
{
32803279
ImGuiID seed = IDStack.back();
32813280
ImGuiID id = ImHashData(&ptr, sizeof(void*), seed);
3282-
ImGui::KeepAliveID(id);
32833281
ImGuiContext& g = *GImGui;
32843282
if (g.DebugHookIdInfo == id)
32853283
ImGui::DebugHookIdInfo(id, ImGuiDataType_Pointer, ptr, NULL);
@@ -3290,7 +3288,6 @@ ImGuiID ImGuiWindow::GetID(int n)
32903288
{
32913289
ImGuiID seed = IDStack.back();
32923290
ImGuiID id = ImHashData(&n, sizeof(n), seed);
3293-
ImGui::KeepAliveID(id);
32943291
ImGuiContext& g = *GImGui;
32953292
if (g.DebugHookIdInfo == id)
32963293
ImGui::DebugHookIdInfo(id, ImGuiDataType_S32, (void*)(intptr_t)n, NULL);
@@ -3333,7 +3330,6 @@ ImGuiID ImGuiWindow::GetIDFromRectangle(const ImRect& r_abs)
33333330
ImGuiID seed = IDStack.back();
33343331
ImRect r_rel = ImGui::WindowRectAbsToRel(this, r_abs);
33353332
ImGuiID id = ImHashData(&r_rel, sizeof(r_rel), seed);
3336-
ImGui::KeepAliveID(id);
33373333
return id;
33383334
}
33393335

@@ -3436,6 +3432,8 @@ ImGuiID ImGui::GetHoveredID()
34363432
return g.HoveredId ? g.HoveredId : g.HoveredIdPreviousFrame;
34373433
}
34383434

3435+
// This is called by ItemAdd().
3436+
// Code not using ItemAdd() may need to call this manually otherwise ActiveId will be cleared. In IMGUI_VERSION_NUM < 18717 this was called by GetID().
34393437
void ImGui::KeepAliveID(ImGuiID id)
34403438
{
34413439
ImGuiContext& g = *GImGui;
@@ -5625,6 +5623,7 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s
56255623
if (resize_rect.Min.x > resize_rect.Max.x) ImSwap(resize_rect.Min.x, resize_rect.Max.x);
56265624
if (resize_rect.Min.y > resize_rect.Max.y) ImSwap(resize_rect.Min.y, resize_rect.Max.y);
56275625
ImGuiID resize_grip_id = window->GetID(resize_grip_n); // == GetWindowResizeCornerID()
5626+
KeepAliveID(resize_grip_id);
56285627
ButtonBehavior(resize_rect, resize_grip_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus);
56295628
//GetForegroundDrawList(window)->AddRect(resize_rect.Min, resize_rect.Max, IM_COL32(255, 255, 0, 255));
56305629
if (hovered || held)
@@ -5660,6 +5659,7 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s
56605659
bool hovered, held;
56615660
ImRect border_rect = GetResizeBorderRect(window, border_n, grip_hover_inner_size, WINDOWS_HOVER_PADDING);
56625661
ImGuiID border_id = window->GetID(border_n + 4); // == GetWindowResizeBorderID()
5662+
KeepAliveID(border_id);
56635663
ButtonBehavior(border_rect, border_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus);
56645664
//GetForegroundDrawLists(window)->AddRect(border_rect.Min, border_rect.Max, IM_COL32(255, 255, 0, 255));
56655665
if ((hovered && g.HoveredIdTimer > WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER) || held)
@@ -8282,6 +8282,8 @@ bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg, ImGu
82828282
// Directional navigation processing
82838283
if (id != 0)
82848284
{
8285+
KeepAliveID(id);
8286+
82858287
// Runs prior to clipping early-out
82868288
// (a) So that NavInitRequest can be honored, for newly opened windows to select a default widget
82878289
// (b) So that we can scroll up/down past clipped items. This adds a small O(N) cost to regular navigation requests
@@ -11046,6 +11048,7 @@ bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags)
1104611048
// We don't need to maintain/call ClearActiveID() as releasing the button will early out this function and trigger !ActiveIdIsAlive.
1104711049
// Rely on keeping other window->LastItemXXX fields intact.
1104811050
source_id = g.LastItemData.ID = window->GetIDFromRectangle(g.LastItemData.Rect);
11051+
KeepAliveID(source_id);
1104911052
bool is_hovered = ItemHoverable(g.LastItemData.Rect, source_id);
1105011053
if (is_hovered && g.IO.MouseClicked[mouse_button])
1105111054
{
@@ -11212,7 +11215,10 @@ bool ImGui::BeginDragDropTarget()
1121211215
const ImRect& display_rect = (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_HasDisplayRect) ? g.LastItemData.DisplayRect : g.LastItemData.Rect;
1121311216
ImGuiID id = g.LastItemData.ID;
1121411217
if (id == 0)
11218+
{
1121511219
id = window->GetIDFromRectangle(display_rect);
11220+
KeepAliveID(id);
11221+
}
1121611222
if (g.DragDropPayload.SourceId == id)
1121711223
return false;
1121811224

imgui.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Index of this file:
6565
// Version
6666
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens)
6767
#define IMGUI_VERSION "1.88 WIP"
68-
#define IMGUI_VERSION_NUM 18716
68+
#define IMGUI_VERSION_NUM 18717
6969
#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx))
7070
#define IMGUI_HAS_TABLE
7171

0 commit comments

Comments
 (0)