Skip to content

Commit

Permalink
IO: set io.KeyModsPrev in EndFrame() to tolerate backend writing to i…
Browse files Browse the repository at this point in the history
…o.KeyMods without breaking. (ocornut#4439)

Amend ff428f1
  • Loading branch information
ocornut authored and AnClark committed Aug 30, 2021
1 parent b61049a commit ed9c5a7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4049,7 +4049,6 @@ void ImGui::NewFrame()

// Update keyboard input state
// Synchronize io.KeyMods with individual modifiers io.KeyXXX bools
g.IO.KeyModsPrev = g.IO.KeyMods;
g.IO.KeyMods = GetMergedKeyModFlags();
memcpy(g.IO.KeysDownDurationPrev, g.IO.KeysDownDuration, sizeof(g.IO.KeysDownDuration));
for (int i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++)
Expand Down Expand Up @@ -4487,6 +4486,7 @@ void ImGui::EndFrame()
// Clear Input data for next frame
g.IO.MouseWheel = g.IO.MouseWheelH = 0.0f;
g.IO.InputQueueCharacters.resize(0);
g.IO.KeyModsPrev = g.IO.KeyMods; // doing it here is better than in NewFrame() as we'll tolerate backend writing to KeyMods. If we want to firmly disallow it we should detect it.
memset(g.IO.NavInputs, 0, sizeof(g.IO.NavInputs));

CallContextHooks(&g, ImGuiContextHookType_EndFramePost);
Expand Down

0 comments on commit ed9c5a7

Please sign in to comment.