From 9bd205a527d28deebed8302f6d93882fcb6b6c04 Mon Sep 17 00:00:00 2001 From: Quantum Date: Thu, 19 Aug 2021 15:57:20 -0400 Subject: [PATCH] [client] imgui: fix modifier key modification race imgui really hates it when we update the modifier key state after igNewFrame. The result is: void ImGui::ErrorCheckEndFrameSanityChecks(): Assertion `(key_mod_flags == 0 || g.IO.KeyMods == key_mod_flags) && "Mismatching io.KeyCtrl/io.KeyShift/io.KeyAlt/io.KeySuper vs io.KeyMods"' failed. Therefore, we buffer the modifier state information and update it in the IO object right before we call igNewFrame. --- client/src/app.c | 13 +++++++++---- client/src/main.h | 4 ++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/client/src/app.c b/client/src/app.c index 416433ef..58d9e304 100644 --- a/client/src/app.c +++ b/client/src/app.c @@ -406,10 +406,10 @@ void app_handleKeyboardTyped(const char * typed) void app_handleKeyboardModifiers(bool ctrl, bool shift, bool alt, bool super) { - g_state.io->KeyCtrl = ctrl; - g_state.io->KeyShift = shift; - g_state.io->KeyAlt = alt; - g_state.io->KeySuper = super; + g_state.modCtrl = ctrl; + g_state.modShift = shift; + g_state.modAlt = alt; + g_state.modSuper = super; } void app_handleKeyboardLEDs(bool numLock, bool capsLock, bool scrollLock) @@ -806,6 +806,11 @@ int app_renderOverlay(struct Rect * rects, int maxRects) struct Overlay * overlay; struct Rect buffer[MAX_OVERLAY_RECTS]; + g_state.io->KeyCtrl = g_state.modCtrl; + g_state.io->KeyShift = g_state.modShift; + g_state.io->KeyAlt = g_state.modAlt; + g_state.io->KeySuper = g_state.modSuper; + igNewFrame(); if (g_state.overlayInput) diff --git a/client/src/main.h b/client/src/main.h index 1457a1d2..b75c65c3 100644 --- a/client/src/main.h +++ b/client/src/main.h @@ -56,6 +56,10 @@ struct AppState bool overlayInput; ImGuiMouseCursor cursorLast; char * imGuiIni; + bool modCtrl; + bool modShift; + bool modAlt; + bool modSuper; bool alertShow; char * alertMessage;