From d1826522111bec39110fcbfb3fa3387a4ea7c905 Mon Sep 17 00:00:00 2001 From: Amos <48657826+Mauler125@users.noreply.github.com> Date: Sun, 16 Jan 2022 00:59:20 +0100 Subject: [PATCH] Check and clear console vector even if console is not drawn The vector could still overflow if user plays the game for a long time while not opening the console at least once. --- r5dev/client/cdll_engine_int.cpp | 3 ++- r5dev/gameui/IConsole.cpp | 31 +++++++++++++++++++------------ r5dev/gameui/IConsole.h | 1 + 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/r5dev/client/cdll_engine_int.cpp b/r5dev/client/cdll_engine_int.cpp index 0110c68b..f36b1071 100644 --- a/r5dev/client/cdll_engine_int.cpp +++ b/r5dev/client/cdll_engine_int.cpp @@ -10,6 +10,7 @@ #include "engine/net_chan.h" #include "public/include/bansystem.h" #include "vpc/keyvalues.h" +#include "gameui/IConsole.h" /*****************************************************************************/ //----------------------------------------------------------------------------- @@ -97,7 +98,7 @@ void __fastcall HFrameStageNotify(CHLClient* rcx, ClientFrameStage_t frameStage) break; } } - + g_pIConsole->Think(); CHLClient_FrameStageNotify(rcx, (int)frameStage); } diff --git a/r5dev/gameui/IConsole.cpp b/r5dev/gameui/IConsole.cpp index dd19f89b..b82c7587 100644 --- a/r5dev/gameui/IConsole.cpp +++ b/r5dev/gameui/IConsole.cpp @@ -60,18 +60,6 @@ void CConsole::Draw(const char* pszTitle, bool* bDraw) SetStyleVar(); m_bInitialized = true; } - if (g_pImGuiConfig->IConsole_Config.m_bAutoClear) // Check if Auto-Clear is enabled. - { - // Loop and clear the beginning of the vector until we are below our limit. - while (m_ivConLog.Size > g_pImGuiConfig->IConsole_Config.m_nAutoClearLimit) - { - m_ivConLog.erase(m_ivConLog.begin()); - } - while (m_ivHistory.Size > 512) - { - m_ivHistory.erase(m_ivHistory.begin()); - } - } //ImGui::ShowStyleEditor(); @@ -214,6 +202,25 @@ void CConsole::Options() ImGui::EndPopup(); } +//----------------------------------------------------------------------------- +// Purpose: runs tasks for the console while not being drawn +//----------------------------------------------------------------------------- +void CConsole::Think() +{ + if (g_pImGuiConfig->IConsole_Config.m_bAutoClear) // Check if Auto-Clear is enabled. + { + // Loop and clear the beginning of the vector until we are below our limit. + while (m_ivConLog.Size > g_pImGuiConfig->IConsole_Config.m_nAutoClearLimit) + { + m_ivConLog.erase(m_ivConLog.begin()); + } + while (m_ivHistory.Size > 512) + { + m_ivHistory.erase(m_ivHistory.begin()); + } + } +} + //----------------------------------------------------------------------------- // Purpose: executes submitted commands in a separate thread //----------------------------------------------------------------------------- diff --git a/r5dev/gameui/IConsole.h b/r5dev/gameui/IConsole.h index b451698c..46025246 100644 --- a/r5dev/gameui/IConsole.h +++ b/r5dev/gameui/IConsole.h @@ -25,6 +25,7 @@ public: void Draw(const char* title, bool* bDraw); void Options(); + void Think(); void ProcessCommand(const char* command_line); int TextEditCallback(ImGuiInputTextCallbackData* data);