← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1638280-coroutine-messages into lp:widelands


GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1638280-coroutine-messages into lp:widelands.

Commit message:
Do not broadcast Lua coroutine error messages to empty player slots. Also, use richtext_escape on them.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1638280 in widelands: "Adding wrong ware per script crashes game"

For more details, see:

To reproduce the crash, add an unused ware to a prefilled building in a starting condition and close a player slot.

With the changes in this branch, players should get a coroutine error message instead of a crash.
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1638280-coroutine-messages into lp:widelands.
=== modified file 'src/logic/cmd_luacoroutine.cc'
--- src/logic/cmd_luacoroutine.cc	2018-05-05 17:10:37 +0000
+++ src/logic/cmd_luacoroutine.cc	2018-07-06 13:44:10 +0000
@@ -23,6 +23,7 @@
 #include "base/log.h"
 #include "base/macros.h"
+#include "graphic/text_layout.h"
 #include "io/fileread.h"
 #include "io/filewrite.h"
 #include "logic/game.h"
@@ -53,8 +54,13 @@
 		for (int i = 1; i <= game.map().get_nrplayers(); i++) {
 			std::unique_ptr<Message> msg(new Widelands::Message(
 			   Message::Type::kGameLogic, game.get_gametime(), "Coroutine",
-			   "images/ui_basic/menu_help.png", "Lua Coroutine Failed", e.what()));
-			game.get_player(i)->add_message(game, std::move(msg), true);
+			   "images/ui_basic/menu_help.png", "Lua Coroutine Failed", richtext_escape(e.what())));
+			// Do not send message to closed player slots
+			Player* recipient = game.get_player(i);
+			if (recipient) {
+				recipient->add_message(game, std::move(msg), true);
+			}

Follow ups