Skip to content

Commit 26785fd

Browse files
committed
Internals: NewFrame: move the window reset loop higher up, namely before UpdateHoveredWindowAndCaptureFlags() -> FindHoveredWindowEx().
This allows using FindHoveredWindowEx() from anywhere in the frame.
1 parent 797101a commit 26785fd

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

imgui.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5158,8 +5158,25 @@ void ImGui::NewFrame()
51585158
// Update mouse input state
51595159
UpdateMouseInputs();
51605160

5161+
// Mark all windows as not visible and compact unused memory.
5162+
IM_ASSERT(g.WindowsFocusOrder.Size <= g.Windows.Size);
5163+
const float memory_compact_start_time = (g.GcCompactAll || g.IO.ConfigMemoryCompactTimer < 0.0f) ? FLT_MAX : (float)g.Time - g.IO.ConfigMemoryCompactTimer;
5164+
for (ImGuiWindow* window : g.Windows)
5165+
{
5166+
window->WasActive = window->Active;
5167+
window->Active = false;
5168+
window->WriteAccessed = false;
5169+
window->BeginCountPreviousFrame = window->BeginCount;
5170+
window->BeginCount = 0;
5171+
5172+
// Garbage collect transient buffers of recently unused windows
5173+
if (!window->WasActive && !window->MemoryCompacted && window->LastTimeActive < memory_compact_start_time)
5174+
GcCompactTransientWindowBuffers(window);
5175+
}
5176+
51615177
// Find hovered window
51625178
// (needs to be before UpdateMouseMovingWindowNewFrame so we fill g.HoveredWindowUnderMovingWindow on the mouse release frame)
5179+
// (currently needs to be done after the WasActive=Active loop and FindHoveredWindowEx uses ->Active)
51635180
UpdateHoveredWindowAndCaptureFlags();
51645181

51655182
// Handle user moving window with mouse (at the beginning of the frame to avoid input lag or sheering)
@@ -5181,22 +5198,6 @@ void ImGui::NewFrame()
51815198
// Mouse wheel scrolling, scale
51825199
UpdateMouseWheel();
51835200

5184-
// Mark all windows as not visible and compact unused memory.
5185-
IM_ASSERT(g.WindowsFocusOrder.Size <= g.Windows.Size);
5186-
const float memory_compact_start_time = (g.GcCompactAll || g.IO.ConfigMemoryCompactTimer < 0.0f) ? FLT_MAX : (float)g.Time - g.IO.ConfigMemoryCompactTimer;
5187-
for (ImGuiWindow* window : g.Windows)
5188-
{
5189-
window->WasActive = window->Active;
5190-
window->Active = false;
5191-
window->WriteAccessed = false;
5192-
window->BeginCountPreviousFrame = window->BeginCount;
5193-
window->BeginCount = 0;
5194-
5195-
// Garbage collect transient buffers of recently unused windows
5196-
if (!window->WasActive && !window->MemoryCompacted && window->LastTimeActive < memory_compact_start_time)
5197-
GcCompactTransientWindowBuffers(window);
5198-
}
5199-
52005201
// Garbage collect transient buffers of recently unused tables
52015202
for (int i = 0; i < g.TablesLastTimeActive.Size; i++)
52025203
if (g.TablesLastTimeActive[i] >= 0.0f && g.TablesLastTimeActive[i] < memory_compact_start_time)
@@ -5660,7 +5661,7 @@ void ImGui::FindHoveredWindowEx(const ImVec2& pos, bool find_first_and_in_any_vi
56605661
{
56615662
ImGuiWindow* window = g.Windows[i];
56625663
IM_MSVC_WARNING_SUPPRESS(28182); // [Static Analyzer] Dereferencing NULL pointer.
5663-
if (!window->Active || window->Hidden)
5664+
if (!window->WasActive || window->Hidden)
56645665
continue;
56655666
if (window->Flags & ImGuiWindowFlags_NoMouseInputs)
56665667
continue;

0 commit comments

Comments
 (0)