Skip to content

Commit

Permalink
TabBar: Added extra mis-usage error recovery. Past the assert, common…
Browse files Browse the repository at this point in the history
… mis-usage don't lead to hard crashes any more, facilitating integration with scripting languages. (#1651)
  • Loading branch information
ocornut committed Feb 22, 2019
1 parent 0f83145 commit 9da48c1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Other Changes:
- InputText: Fixed an edge case crash that would happen if another widget sharing the same ID
is being swapped with an InputText that has yet to be activated.
- TabBar: Fixed a crash when using BeginTabBar() recursively (didn't affect docking). (#2371)
- TabBar: Added extra mis-usage error recovery. Past the assert, common mis-usage don't lead to
hard crashes any more, facilitating integration with scripting languages. (#1651)
- Examples: OpenGL: Fix for OSX not supporting OpenGL 4.5, we don't try to read GL_CLIP_ORIGIN
even if the OpenGL headers/loader happens to define the value. (#2366, #2186)

Expand Down
18 changes: 15 additions & 3 deletions imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5993,7 +5993,11 @@ void ImGui::EndTabBar()
return;

ImGuiTabBar* tab_bar = g.CurrentTabBar;
IM_ASSERT(tab_bar != NULL && "Mismatched BeginTabBar()/EndTabBar()!");
if (tab_bar == NULL)
{
IM_ASSERT(tab_bar != NULL && "Mismatched BeginTabBar()/EndTabBar()!");
return; // FIXME-ERRORHANDLING
}
if (tab_bar->WantLayout)
TabBarLayout(tab_bar);

Expand Down Expand Up @@ -6376,7 +6380,11 @@ bool ImGui::BeginTabItem(const char* label, bool* p_open, ImGuiTabItemFlags f
return false;

ImGuiTabBar* tab_bar = g.CurrentTabBar;
IM_ASSERT(tab_bar && "Needs to be called between BeginTabBar() and EndTabBar()!");
if (tab_bar == NULL)
{
IM_ASSERT(tab_bar && "Needs to be called between BeginTabBar() and EndTabBar()!");
return false; // FIXME-ERRORHANDLING
}
bool ret = TabItemEx(tab_bar, label, p_open, flags);
if (ret && !(flags & ImGuiTabItemFlags_NoPushId))
{
Expand All @@ -6393,7 +6401,11 @@ void ImGui::EndTabItem()
return;

ImGuiTabBar* tab_bar = g.CurrentTabBar;
IM_ASSERT(tab_bar != NULL && "Needs to be called between BeginTabBar() and EndTabBar()!");
if (tab_bar == NULL)
{
IM_ASSERT(tab_bar != NULL && "Needs to be called between BeginTabBar() and EndTabBar()!");
return;
}
IM_ASSERT(tab_bar->LastTabItemIdx >= 0);
ImGuiTabItem* tab = &tab_bar->Tabs[tab_bar->LastTabItemIdx];
if (!(tab->Flags & ImGuiTabItemFlags_NoPushId))
Expand Down

0 comments on commit 9da48c1

Please sign in to comment.