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:
Chris Beck 2014-12-02 21:57:12 -05:00
parent c6d8f03c5f
commit 77e846976b
2 changed files with 9 additions and 0 deletions

View File

@ -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();
}

View File

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