ImGui: don't use textures for autocomplete if the loading failed

Otherwise the indices will be incorrect and will cause undefined behavior.
This commit is contained in:
Kawe Mazidjatari 2024-03-01 14:06:09 +01:00
parent 7f36220448
commit 0b8017d3e6
2 changed files with 9 additions and 3 deletions

View File

@ -392,7 +392,7 @@ void CConsole::DrawAutoCompletePanel(void)
ImGui::PushID(static_cast<int>(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<unsigned char*>(rFlagIcon.m_pData), // !TODO: Fall-back texture.
static_cast<int>(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;
}

View File

@ -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;