Skip to content

Commit

Permalink
ensure that unbalanced tags do not pop too many colors off the stack
Browse files Browse the repository at this point in the history
  • Loading branch information
db48x committed May 19, 2024
1 parent e902206 commit dec5cf3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/cata_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,15 +393,17 @@ 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 ) {
case color_tag_parse_result::open_color_tag:
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
Expand Down Expand Up @@ -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 );
}

Expand Down

0 comments on commit dec5cf3

Please sign in to comment.