From d08f402ef1677a8389c9cdd0040d1c18a085d9f1 Mon Sep 17 00:00:00 2001 From: gfgtdf Date: Wed, 6 Sep 2017 02:28:49 +0200 Subject: [PATCH] fix 'at_end()' assertion faliure when chatting in a mp game See #1857 This commit does 2 things: 1) Ensure that if the replay pos was at_end before a speak was added it will still be at end after the speak was added, fixes the mentioned assertion failure. 2) Make unsyced map_labels use the same logic as speak, this fixes OOS issues when the 'back to turn' mp feature was used in mp, since previously adding map labels while watching a mp replay (is the really possible? not 100% sure) might cause mismatches of replay_pos of other savegames with the current replay data. --- src/replay.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/replay.cpp b/src/replay.cpp index 1c33b4db5b5d..83c506e45d6e 100644 --- a/src/replay.cpp +++ b/src/replay.cpp @@ -337,8 +337,7 @@ bool replay::add_chat_message_location(int pos) void replay::speak(const config& cfg) { - config& cmd = base_->insert_command(base_->size()); - cmd["undo"] = false; + config& cmd = add_nonundoable_command(); cmd.add_child("speak",cfg); add_chat_message_location(base_->size() - 1); } @@ -581,9 +580,13 @@ config& replay::add_command() config& replay::add_nonundoable_command() { - config& r = base_->insert_command(base_->get_pos()); + const bool was_at_end = at_end(); + config& r = base_->insert_command(base_->size()); r["undo"] = false; - base_->set_pos(base_->get_pos() + 1); + if(was_at_end) { + base_->set_pos(base_->get_pos() + 1); + } + assert(was_at_end == at_end()); return r; }