@@ -5158,8 +5158,25 @@ void ImGui::NewFrame()
5158
5158
// Update mouse input state
5159
5159
UpdateMouseInputs();
5160
5160
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
+
5161
5177
// Find hovered window
5162
5178
// (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)
5163
5180
UpdateHoveredWindowAndCaptureFlags();
5164
5181
5165
5182
// 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()
5181
5198
// Mouse wheel scrolling, scale
5182
5199
UpdateMouseWheel();
5183
5200
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
-
5200
5201
// Garbage collect transient buffers of recently unused tables
5201
5202
for (int i = 0; i < g.TablesLastTimeActive.Size; i++)
5202
5203
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
5660
5661
{
5661
5662
ImGuiWindow* window = g.Windows[i];
5662
5663
IM_MSVC_WARNING_SUPPRESS(28182); // [Static Analyzer] Dereferencing NULL pointer.
5663
- if (!window->Active || window->Hidden)
5664
+ if (!window->WasActive || window->Hidden)
5664
5665
continue;
5665
5666
if (window->Flags & ImGuiWindowFlags_NoMouseInputs)
5666
5667
continue;
0 commit comments