Internals: CallContextHooks(): fixed iterating a reallocated array when a hook callback adds a hook. (#9590)

Note that Test Engine GuiFunc code is called within a hook anyhow.
This commit is contained in:
Michał Cichoń 2026-10-23 14:22:52 +02:00 committed by GitHub
parent 4be0b47ecc
commit 7bd38119c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4740,12 +4740,13 @@ void ImGui::RemoveContextHook(ImGuiContext* ctx, ImGuiID hook_id)
// Call context hooks (used by e.g. test engine)
// We assume a small number of hooks so all stored in same array
// Iterate by index: a callback may add a hook, which reallocates the array. Hooks added here are called from the next call.
void ImGui::CallContextHooks(ImGuiContext* ctx, ImGuiContextHookType hook_type)
{
ImGuiContext& g = *ctx;
for (ImGuiContextHook& hook : g.Hooks)
if (hook.Type == hook_type)
hook.Callback(&g, &hook);
for (int n = 0, hooks_count = g.Hooks.Size; n < hooks_count; n++)
if (g.Hooks[n].Type == hook_type)
g.Hooks[n].Callback(&g, &g.Hooks[n]);
}
//-----------------------------------------------------------------------------