mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-01 11:49:20 +00:00
bugfix: fix an infinite loop in gui1 textbox when run with no gui
The infinite loop was that when the textbox has no space, we word wrap a single character infinitely and run out of memory by printing endlines.
This commit is contained in:
parent
c6d8f03c5f
commit
77e846976b
@ -39,6 +39,9 @@ static lg::log_domain log_network("network");
|
||||
#define LOG_NW LOG_STREAM(info, log_network)
|
||||
#define ERR_NW LOG_STREAM(err, log_network)
|
||||
|
||||
static lg::log_domain log_mp("mp/main");
|
||||
#define DBG_MP LOG_STREAM(debug, log_mp)
|
||||
|
||||
namespace {
|
||||
/** The maximum number of messages in the chat history. */
|
||||
const size_t max_messages = 256;
|
||||
@ -113,10 +116,12 @@ void chat::init_textbox(gui::textbox& textbox)
|
||||
|
||||
void chat::update_textbox(gui::textbox& textbox)
|
||||
{
|
||||
//DBG_MP << "update_textbox...\n";
|
||||
for(msg_hist::const_iterator itor = message_history_.begin() + last_update_;
|
||||
itor != message_history_.end(); ++itor) {
|
||||
textbox.append_text(format_message(*itor), true, color_message(*itor));
|
||||
}
|
||||
//DBG_MP << "update_textbox end\n";
|
||||
|
||||
last_update_ = message_history_.size();
|
||||
}
|
||||
|
@ -332,6 +332,10 @@ surface textbox::add_text_line(const ucs4::string& text, const SDL_Color& color)
|
||||
char_y_.erase(char_y_.end()-backup, char_y_.end());
|
||||
wrapped_text.erase(wrapped_text.end()-backup, wrapped_text.end());
|
||||
}
|
||||
} else {
|
||||
if (visible_string == std::string("").append(unicode_cast<utf8::string>(*itor))) {
|
||||
break; //breaks infinite loop where when running with a fake display, we word wrap a single character infinitely.
|
||||
}
|
||||
}
|
||||
backup_itor = text.end();
|
||||
wrapped_text.push_back(ucs4::char_t('\n'));
|
||||
|
Loading…
x
Reference in New Issue
Block a user