Skip to content

Commit

Permalink
Debug: move debug assertion in post-clip code to reduce overhead. (#4796
Browse files Browse the repository at this point in the history
 and more).

Amend c801799
  • Loading branch information
ocornut committed Dec 20, 2023
1 parent 1e10130 commit 8340a30
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9613,6 +9613,7 @@ void ImGuiStackSizes::CompareWithContextState(ImGuiContext* ctx)
// Advance cursor given item size for layout.
// Register minimum needed size so it can extend the bounding box used for auto-fit calculation.
// See comments in ItemAdd() about how/why the size provided to ItemSize() vs ItemAdd() may often different.
// THIS IS IN THE PERFORMANCE CRITICAL PATH.
void ImGui::ItemSize(const ImVec2& size, float text_baseline_y)
{
ImGuiContext& g = *GImGui;
Expand Down Expand Up @@ -9652,6 +9653,7 @@ void ImGui::ItemSize(const ImVec2& size, float text_baseline_y)
// Declare item bounding box for clipping and interaction.
// Note that the size can be different than the one provided to ItemSize(). Typically, widgets that spread over available surface
// declare their minimum size requirement to ItemSize() and provide a larger region to ItemAdd() which is used drawing/interaction.
// THIS IS IN THE PERFORMANCE CRITICAL PATH (UNTIL THE CLIPPING TEST AND EARLY-RETURN)
bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg, ImGuiItemFlags extra_flags)
{
ImGuiContext& g = *GImGui;
Expand All @@ -9666,11 +9668,11 @@ bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg, ImGu
g.LastItemData.StatusFlags = ImGuiItemStatusFlags_None;
// Note: we don't copy 'g.NextItemData.SelectionUserData' to an hypothetical g.LastItemData.SelectionUserData: since the former is not cleared.

// Directional navigation processing
if (id != 0)
{
KeepAliveID(id);

// Directional navigation processing
// Runs prior to clipping early-out
// (a) So that NavInitRequest can be honored, for newly opened windows to select a default widget
// (b) So that we can scroll up/down past clipped items. This adds a small O(N) cost to regular navigation requests
Expand All @@ -9689,12 +9691,9 @@ bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg, ImGu
if (window == g.NavWindow || ((window->Flags | g.NavWindow->Flags) & ImGuiWindowFlags_NavFlattened))
NavProcessItem();
}

// [DEBUG] People keep stumbling on this problem and using "" as identifier in the root of a window instead of "##something".
// Empty identifier are valid and useful in a small amount of cases, but 99.9% of the time you want to use "##something".
// READ THE FAQ: https://dearimgui.com/faq
IM_ASSERT(id != window->ID && "Cannot have an empty ID at the root of a window. If you need an empty label, use ## and read the FAQ about how the ID Stack works!");
}

// Lightweight clear of SetNextItemXXX data.
g.NextItemData.Flags = ImGuiNextItemDataFlags_None;
g.NextItemData.ItemFlags = ImGuiItemFlags_None;

Expand All @@ -9704,7 +9703,7 @@ bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg, ImGu
#endif

// Clipping test
// (FIXME: This is a modified copy of IsClippedEx() so we can reuse the is_rect_visible value)
// (this is a modified copy of IsClippedEx() so we can reuse the is_rect_visible value)
//const bool is_clipped = IsClippedEx(bb, id);
//if (is_clipped)
// return false;
Expand All @@ -9716,12 +9715,20 @@ bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg, ImGu

// [DEBUG]
#ifndef IMGUI_DISABLE_DEBUG_TOOLS
if (id != 0 && id == g.DebugLocateId)
DebugLocateItemResolveWithLastItem();
#endif
if (id != 0)
{
if (id == g.DebugLocateId)
DebugLocateItemResolveWithLastItem();

// [DEBUG] People keep stumbling on this problem and using "" as identifier in the root of a window instead of "##something".
// Empty identifier are valid and useful in a small amount of cases, but 99.9% of the time you want to use "##something".
// READ THE FAQ: https://dearimgui.com/faq
IM_ASSERT(id != window->ID && "Cannot have an empty ID at the root of a window. If you need an empty label, use ## and read the FAQ about how the ID Stack works!");
}
//if (g.IO.KeyAlt) window->DrawList->AddRect(bb.Min, bb.Max, IM_COL32(255,255,0,120)); // [DEBUG]
//if ((g.LastItemData.InFlags & ImGuiItemFlags_NoNav) == 0)
// window->DrawList->AddRect(g.LastItemData.NavRect.Min, g.LastItemData.NavRect.Max, IM_COL32(255,255,0,255)); // [DEBUG]
#endif

// We need to calculate this now to take account of the current clipping rectangle (as items like Selectable may change them)
if (is_rect_visible)
Expand Down

1 comment on commit 8340a30

@Hdiupm
Copy link

@Hdiupm Hdiupm commented on 8340a30 Dec 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot_20231220-215340
Screenshot_20231219-212237

I Just Update The Files from 1.85 to 1.90
But the version This version has a lot of problems and I tried to solve them but I couldn’t (I use a mobile phone)

If the pictures are not clear or do not exist, I will explain it here :

1- the error in ImGui.h file in ImGuiStyle::ScaleAllSizes

2- the error is (invalid operands to binary expression ('ImVec2' and 'float')
3- in padding variables like
ItemSpacing = ImFloor(ItemSpacing * scale_factor);
WindowPadding = ImFloor(WindowPadding * scale_factor);

5- another error (invalid operands to binary expression ('const ImVec2' and 'ImVec2')

In this code

float dist2 = ImLengthSqr(p - p_line);

Please Fix Errors ❤️

Please sign in to comment.