From dec5cf3e5c5279d6d4d216632fdb7ea155add458 Mon Sep 17 00:00:00 2001 From: Daniel Brooks Date: Sun, 19 May 2024 08:46:40 -0700 Subject: [PATCH] ensure that unbalanced tags do not pop too many colors off the stack --- src/cata_imgui.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cata_imgui.cpp b/src/cata_imgui.cpp index a3c729bd2d7db..c76cd74b0d14d 100644 --- a/src/cata_imgui.cpp +++ b/src/cata_imgui.cpp @@ -393,7 +393,7 @@ void cataimgui::imvec2_to_point( ImVec2 *src, point *dest ) } } -static void PushOrPopColor( const std::string_view seg ) +static void PushOrPopColor( const std::string_view seg, int minimumColorStackSize ) { color_tag_parse_result tag = get_color_from_tag( seg, report_color_error::yes ); switch( tag.type ) { @@ -401,7 +401,9 @@ static void PushOrPopColor( const std::string_view seg ) ImGui::PushStyleColor( ImGuiCol_Text, tag.color ); break; case color_tag_parse_result::close_color_tag: - ImGui::PopStyleColor(); + if( GImGui->ColorStack.Size > minimumColorStackSize ) { + ImGui::PopStyleColor(); + } break; case color_tag_parse_result::non_color_tag: // Do nothing @@ -455,7 +457,7 @@ void cataimgui::window::draw_colored_text( std::string const &text, } if( seg[0] == '<' ) { - PushOrPopColor( seg ); + PushOrPopColor( seg, startColorStackCount ); seg = rm_prefix( seg ); }