From a59b704384fefcde9fa3b633f2f1b9ca0184fb39 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Fri, 1 Mar 2024 14:06:09 +0100 Subject: [PATCH] ImGui: don't use textures for autocomplete if the loading failed Otherwise the indices will be incorrect and will cause undefined behavior. --- r5dev/gameui/IConsole.cpp | 7 ++++--- r5dev/gameui/IConsole.h | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/r5dev/gameui/IConsole.cpp b/r5dev/gameui/IConsole.cpp index 30e18dea..723cdd61 100644 --- a/r5dev/gameui/IConsole.cpp +++ b/r5dev/gameui/IConsole.cpp @@ -392,7 +392,7 @@ void CConsole::DrawAutoCompletePanel(void) ImGui::PushID(static_cast(i)); - if (con_autocomplete_window_textures.GetBool()) + if (m_autoCompleteTexturesLoaded && con_autocomplete_window_textures.GetBool()) { // Show the flag texture before the cvar name. const int mainTexIdx = GetFlagTextureIndex(suggest.flags); @@ -772,13 +772,14 @@ bool CConsole::LoadFlagIcons(void) ret = LoadTextureBuffer(reinterpret_cast(rFlagIcon.m_pData), // !TODO: Fall-back texture. static_cast(rFlagIcon.m_nSize), &rFlagIcon.m_idIcon, &rFlagIcon.m_nWidth, &rFlagIcon.m_nHeight); - IM_ASSERT(ret); - if (!ret) { + Assert(0, "Texture flags load failed for %i", i); break; } } + + m_autoCompleteTexturesLoaded = ret; return ret; } diff --git a/r5dev/gameui/IConsole.h b/r5dev/gameui/IConsole.h index c71ad20d..8f2acaef 100644 --- a/r5dev/gameui/IConsole.h +++ b/r5dev/gameui/IConsole.h @@ -149,6 +149,11 @@ private: // the autocomplete window to keep the current selection visible. bool m_autoCompletePosMoved; + // If the textures failed to load, this will remain false and no textures + // will be drawn in the autocomplete window. This is because if one fails + // to load, the indices will be incorrect. + bool m_autoCompleteTexturesLoaded; + // The position and rect of the autocomplete window, the pos is set to that // of the input text field + an offset to move it under the item. ImVec2 m_autoCompleteWindowPos;