TabBar: Fixed using more than 32 KB-worth of tab names. (#4176)
diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt
index b151c65..2c5394c 100644
--- a/docs/CHANGELOG.txt
+++ b/docs/CHANGELOG.txt
@@ -36,6 +36,7 @@
-----------------------------------------------------------------------
Other Changes:
+- TabBar: Fixed using more than 32 KB-worth of tab names. (#4176)
- Demo: Fixed requirement in 1.83 to link with imgui_demo.cpp if IMGUI_DISABLE_METRICS_WINDOW is not set. (#4171)
Normally the right way to disable compiling the demo is to set IMGUI_DISABLE_DEMO_WINDOWS, but we want to avoid
implying that the file is required.
diff --git a/imgui_internal.h b/imgui_internal.h
index 07daa66..d071d72 100644
--- a/imgui_internal.h
+++ b/imgui_internal.h
@@ -1952,7 +1952,7 @@
ImGuiTabItemFlags_Button = 1 << 21 // Used by TabItemButton, change the tab item behavior to mimic a button
};
-// Storage for one active tab item (sizeof() 28~32 bytes)
+// Storage for one active tab item (sizeof() 40 bytes)
struct ImGuiTabItem
{
ImGuiID ID;
@@ -1962,12 +1962,12 @@
float Offset; // Position relative to beginning of tab
float Width; // Width currently displayed
float ContentWidth; // Width of label, stored during BeginTabItem() call
- ImS16 NameOffset; // When Window==NULL, offset to name within parent ImGuiTabBar::TabsNames
+ ImS32 NameOffset; // When Window==NULL, offset to name within parent ImGuiTabBar::TabsNames
ImS16 BeginOrder; // BeginTabItem() order, used to re-order tabs after toggling ImGuiTabBarFlags_Reorderable
ImS16 IndexDuringLayout; // Index only used during TabBarLayout()
bool WantClose; // Marked as closed by SetTabItemClosed()
- ImGuiTabItem() { memset(this, 0, sizeof(*this)); LastFrameVisible = LastFrameSelected = -1; NameOffset = BeginOrder = IndexDuringLayout = -1; }
+ ImGuiTabItem() { memset(this, 0, sizeof(*this)); LastFrameVisible = LastFrameSelected = -1; NameOffset = -1; BeginOrder = IndexDuringLayout = -1; }
};
// Storage for a tab bar (sizeof() 152 bytes)
@@ -2009,7 +2009,7 @@
int GetTabOrder(const ImGuiTabItem* tab) const { return Tabs.index_from_ptr(tab); }
const char* GetTabName(const ImGuiTabItem* tab) const
{
- IM_ASSERT(tab->NameOffset != -1 && (int)tab->NameOffset < TabsNames.Buf.Size);
+ IM_ASSERT(tab->NameOffset != -1 && tab->NameOffset < TabsNames.Buf.Size);
return TabsNames.Buf.Data + tab->NameOffset;
}
};
diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp
index ebac594..a623863 100644
--- a/imgui_widgets.cpp
+++ b/imgui_widgets.cpp
@@ -7765,7 +7765,7 @@
tab->Flags = flags;
// Append name with zero-terminator
- tab->NameOffset = (ImS16)tab_bar->TabsNames.size();
+ tab->NameOffset = (ImS32)tab_bar->TabsNames.size();
tab_bar->TabsNames.append(label, label + strlen(label) + 1);
// Update selected tab